function views_embed_view
Same name in other branches
- 6.x-3.x views.module \views_embed_view()
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
string $name: The name of the view to embed.
string $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
-
./
views.module, line 2489
Code
function views_embed_view($name, $display_id = 'default') {
$args = func_get_args();
// Remove $name.
array_shift($args);
if (count($args)) {
// Remove $display_id.
array_shift($args);
}
$view = views_get_view($name);
if (!$view || !$view->access($display_id)) {
return;
}
return $view->preview($display_id, $args);
}