Skip to main content

Drupal 8: Programmatically render a view as HTML in Controller, Block, Form etc

 Sometimes twig_tweak or drupal core twig render functions won't do the trick for you.

So for example instead of using this directly into your twig file:

{{ drupal_view('my_view', 'block_1', tid) }}

you might want to try this:

\Drupal::service('renderer')->render(views_embed_view('view_id', 'display_id',$arg));

 

views