a77icu5
a77icu5

Reputation: 131

Drupal block_load page

How I cant load a 'page' view within my template. My page view is "foo_bar" and the view file is "views-view-unformatted--foo-bar--page.tpl.php" then I use the next code but it did't load the view.

$block  = block_load('views', 'foo_bar');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
echo $output;

Upvotes: 1

Views: 836

Answers (1)

hugronaphor
hugronaphor

Reputation: 995

There are 2 functions to load a view;

$view = views_get_view('view_name');
  // ensure view exists
  if (!$view)
    return;
  $view->set_display('view_display');
  $view->set_arguments(array($tid));
  //$view->is_cacheable = FALSE; //default
  $view->pre_execute();
  $view->execute();
  $result = $view->render();

or a simpler:

$result = views_embed_view($name, $display_id = 'default'); 

Upvotes: 1

Related Questions