1 views.module | views_embed_view($name, $display_id = 'default') |
Embed a view using a PHP snippet.
This function is meant to be called from PHP snippets, should one wish to embed a view in a node or something. It's meant to provide the simplest solution and doesn't really offer a lot of options, but breaking the function apart is pretty easy, and this provides a worthwhile guide to doing so.
Note that this function does NOT display the title of the view. If you want to do that, you will need to do what this function does manually, by loading the view, getting the preview and then getting $view->get_title().
Parameters
$name: The name of the view to embed.
$display_id: The display id to embed. If unsure, use 'default', as it will always be valid. But things like 'page' or 'block' should work here.
...: Any additional parameters will be passed as arguments.
File
- core/
modules/ views/ views.module, line 1983 - Primarily Backdrop hooks and global API functions to manipulate views.
Code
function views_embed_view($name, $display_id = 'default') {
$args = func_get_args();
array_shift($args); // remove $name
if (count($args)) {
array_shift($args); // remove $display_id
}
$view = views_get_view($name);
if (!$view || !$view->access($display_id)) {
return;
}
return $view->preview($display_id, $args);
}