I put this in my preprocess_node function, so that I can use it when theming a node.

  //
  // ADD ATTACHED VIEWS TO THE NODE TEMPLATE VARIABLES
  //

  //
  // I'M NOT SURE WHAT THIS PART DOES:
  //
  if (isset($node->build_mode)) {
    $mode = $node->build_mode;
    if ($mode == NODE_BUILD_NORMAL) {
        $mode = $node->teaser ? 'teaser' : 'full'; 
    }
  }
  else {
    $mode = 'full'; 
  }

  //
  // HERE IS WHERE I GET THE VIEW
  //
  $views = views_attach_get_node_views($vars['node']->type, $mode);
  foreach ($views as $info) {
    $view = views_get_view($info['name']);
    $view->set_display($info['display']);
    if ($view->access($info['display'])) {
      $view->current_node = $vars['node'];
      $result = $view->execute_display($info['display']);
      if (!empty($result)) {
        $vars['views_attach_'.$view->name.'_'.$info['display']] = $result;
      }
    }
  }

Comments

Wolfgang Reszel’s picture

Hi,

can you post the whole preprocess_node function?

And how to access the view in node.tpl when not using print $content;?

Tekl

Funkymoses’s picture

What file does this go in?

Funkymoses’s picture

A: your template's template.php file.

OnlineWD™’s picture

And what goes in the node template file? Also you might like to include the function, this is not a working example but thanks for your efforts.

hefox’s picture

All valid attached views for a node are available at $node->content['views_attach_'. view name .'_' . display name]['#value'] where view name is the name of the view, and display is the display id (which can be found various ways, I tend to hover over the display tab and look at the url). In general views_attach displays id have the pattern node_content_ [ie node_content_1, node_content_2].

I would not suggest recalling view creation in preprocess considering if the view isn't cache, it's causing the each display to be executed twice. Performance!

$node is available in the preprocess at:

  $variables['node'];

and in the node template files at

 $node
eaton’s picture

Category: bug » feature
Status: Active » Closed (won't fix)

At present there are no plans to auto-render this information into the template variables. If you wanted to do so in your own theme's custom code, though, this would be a place to start.