1

I've added a custom block (which is an image) in the HEADER section of a view. I want to show this image at the top of my page but currently it appears in content views-view.html.twig.

How can I access to this image in page.html.twig?

2

Take away the block from the view header and use twig_tweak module to be able to insert something like this in your twig template

{# No need to configure this block on "admin/structure/block" page. #}
<dt>Block:</dt>
<dd>{{ drupal_block('BLOCKID') }}</dd>

Or if you don't want to use an extra module add to your THEMENAME.theme

function THEMENAME_preprocess_page(&$variables) {
  $block = \Drupal\block\Entity\Block::load('BLOCKID');
  $content = \Drupal::entityTypeManager()->getViewBuilder('block')->view($block);
  $variables['my_block'] = $content;
}

and in your twig template just use

{{ my_block }}
  • Thank you so much. The first approach look better. – Sky Feb 10 '18 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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