0

In my Drupal 8 theme I have a template called __menu.html.twig which gets called in my page.html.twig

I am trying to render a region within the __menu.html.twig where I can place blocks.

I have rendered the region within my theme.info. How can I declare the region in __menu.html.twig?

0

1 Answer 1

0

I'm not sure if this will answer your question as you are stating that you want to render a region in the menu template. You can't do this in the traditional sense but you can use Twig Tweak to render blocks pretty much in any template assuming you have the right context.

See their help pages for good documentation on how to do this.

As an example, to render a block in any template, you'd write something like this:

{{ drupal_block('plugin_id', {label: 'Example'|t, some_setting: 'example', setting_array: {value: value}}) }}

You can also render views and full entities which comes in handy as well, for example:

{{ drupal_entity('block_content', 1) }}

In general, Twig tweak is a super handy module that we use pretty much on most D8/D9 projects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.