I am working with Drupal 8. I have a view page and added a twig for that.
I want to call a block inside my view page. How can I do that?
You can use module Twig Tweak this module you can render view,block ... You can see document here
Render views
{{ drupal_view('who_s_new', 'block_1') }}
Render blocks
{{ drupal_block(plugin_id) }}
Here is some possible ways to do it:
Click ADD next to header or footer area and look for GLOBAL: Rendered entity - Block
. The configuration asks for view mode
and block id
You can use Views block area module that will allow you to insert a block as a field or in header or footer area.
if you want to add the block using your twig template in your THEMENAME.theme
file using a preprocess
function
function THEMENAME_preprocess_XXX (&$variables) {
$block = \Drupal\block\Entity\Block::load('id_block');
$variables['myBlock'] = \Drupal::entityTypeManager()
->getViewBuilder('block')
->view($block);
}
and then inside your twig file use this
{{ myBlock }}
To find appropriate preprocess function look in your twig file comments.
For example if you want to use views-view--unformatted.html.twig
you can see in the comments
* @see template_preprocess_views_view_unformatted()
which means include in your .theme
file THEMENAME_preprocess_views_view_unformatted()
function