Mar 23, 2017 in Drupal 8, Snippets

In some cases you want to embed a view inside your custom module. The views_embed_view() function is the way to go. With this little snippet, you can render any view:

$result = render(views_embed_view('submenu', 'block_1'));
print $result;

In this case, "submenu" is the name of my view and "block_1" is the display id. For more examples, take a look at the function page.