1

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;
4

1 回答 1

1

有 2 个函数可以加载视图;

$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();

或更简单的:

$result = views_embed_view($name, $display_id = 'default'); 
于 2013-09-03T07:14:53.220 回答