You are here

function date_embed_view in Date 6.2

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: 'calendar_1' will display the calendar page, 'calendar_block_1' will display the calendar block.

$settings: an array of view settings to use to override view default values;

Include a setting for 'block_identifier, the identifier to use for this embedded view. All embedded views that use the same identifier will move together, or provide different identifiers to keep them independent. The identifier will be used in the url as a querystring, like: node/27?mini=calendar/2008-10.

...: Any additional parameters will be passed as arguments.

File

./date_api.module, line 2386
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_embed_view($name, $display_id = 'default', $settings = array(), $args = array()) {
  $view = views_get_view($name);
  if (!$view) {
    return;
  }
  if (!empty($settings)) {
    foreach ($settings as $key => $setting) {
      $view->{$key} = $setting;
    }
  }
  if (!isset($view->date_info->block_identifier)) {
    $view->date_info->block_identifier = 'mini';
  }
  return $view
    ->preview($display_id, $args);
}