0

My page--front.html.twig is working ok. I want to print the block_1 display of the recent_comments view. I tried this but it does not seem to work.

{{ view.comments_recent(block_1) }}

2 Answers 2

4

You can preprocess a new variable and use views_embed_view like:

$variables['my_view'] = views_embed_view('view_id', 'display_id');

So in your case:

$variables['my_view'] = views_embed_view('comments_recent', 'block_1');

And then in the twig file:

{{ my_view }}

See views_embed_view. It can also take arguments.

2

You want the Twig Tweak module. It provides a function to render a view directly in a twig template without the need for preprocessing.

https://www.drupal.org/project/twig_tweak

It also provides a few other functions which might come in handy.

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.