How do I print an exposed filter block in a template file?

id flag

I have a view with an exposed taxonomy filter. I configured it to be displayed as a separate block so that I can print it another twig template. I tried this.

 * Implements hook_preprocess_block() for block.html.twig.
 function themename_preprocess_block(array &$variables) {
   $variables['featured'] = views_embed_view('view_name', 'contextual_filter_block_machine_name');

Then I used {{ featured }} in the block template, but it doesn't work.

Is there another way to do this?

Chris Happy avatar
cg flag
Did you rename `themename` to be your theme's machine name? Also, can you run a `debug(json_encode(views_embed_view('view_name', 'contextual_filter_block_machine_name')))` and then check the "Recent Log Reports" page?
id flag

I used another approach to solve the problem. I overrode the views template to print the exposed filter where I wanted. You can get it as

{{ exposed}}

in the twig template.


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.