Score:0

Render block in a view twig template

cn flag

I need to render the output of a block within a view / node template (node--news--full.html.twig). Using {{ page.blockName }} does not return anything as {{ page }} within a node view simply returns a boolean (as expected within a node twig template).

Any ideas?

Score:4
cn flag

The Twig Tweak module can print blocks:

{# Print block using default configuration. #}
{{ drupal_block('system_branding_block') }}

{# Print block using custom configuration. #}
{{ drupal_block('system_branding_block', {label: 'Branding', use_site_name: false, id}) }}

{# Bypass block.html.twig theming. #}
{{ drupal_block('system_branding_block', wrapper=false) }}

Or use the views module itself

In the views admin UI, you can add a block to the Header, Footer, or No results behavior areas. Just click Add and then select Rendered entity - Block.

Score:0
cn flag

Another possibility is to get the block to render array in views/node preprocess functions in theme/module and send it to the template through $variables.

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.