Score:0

Is it possible to render a region in a menu template?

zw flag

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?

Score:0
ng flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.