Embed a view in Drupal 8 code

Tim Rabbetts | September 14, 2020

Sometimes its useful to embed a view in some code in Drupal 8.  Its also useful to pass arguments.  

Within the view you need to setup a contextual filter whicyh alolwos you to pass in arguments.  most likely you will want the allow multiple option on.

Embed view

Then this code can be used to embed the view.

$show_nids = [123,456,444];

$showsView = views_embed_view('shows', 'block_1', implode($show_nids, '+'));