0

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?

1
  • 1
    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? Commented May 30, 2022 at 20:52

2 Answers 2

1

I almost always use the twig_tweak module, there is 3 ways to render a block. You can see the doc here Twig tweak Block render, you should probably use

drush ev "print_r(array_keys(\Drupal::service('plugin.manager.block')->getDefinitions()));"

find your block in the list and then use

{{ drupal_block('your_block_id') }}
0

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.

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.