views_embed_view

Versions
6 – 7
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.

▾ 9 functions call views_embed_view()

cck_gallery_block in contributions/cck_gallery/cck_gallery.module
Implementation of hook_block().
cck_gallery_preprocess_node in contributions/cck_gallery/cck_gallery.module
cck_gallery_preprocess_views_view_list__gallery_list_page in contributions/cck_gallery/cck_gallery.module
facebook_status_box in contributions/facebook_status/facebook_status.module
The status form.
nodecomment_form_alter in contributions/nodecomment/nodecomment.module
Implementation of hook_form_alter().
nodecomment_render in contributions/nodecomment/nodecomment.module
Node comment's version of comment_render, to render all comments on a node.
rules_scheduler_form in contributions/rules/rules_scheduler/rules_scheduler.admin.inc
Builds the scheduling page with a form for manual scheduling and deletion of tasks.
theme_field_formatter_og_views_default in contributions/og/og_views/og_views.module
Organic group views field formatter.
_facebook_status_conversation in contributions/facebook_status/facebook_status.conversation.inc
Builds a page with a conversation view. A form to post a message to the other user's profile may be at the top. If it is and if the user has JavaScript enabled in their browser, the view will update via AJAX when the message is submitted.

Code

contributions/views/views.module, line 1151

<?php
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);
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.