Skip to main content

Embed a view in Drupal 8 code

Updated by Tim Rabbetts on
white, window, glass

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, '+'));

 

Add new comment