0

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?

2 Answers 2

4

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.

0

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.

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.