Closed (won't fix)
Project:
Views attach
Version:
6.x-2.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Mar 2010 at 02:10 UTC
Updated:
10 Oct 2010 at 01:58 UTC
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
Comment #1
Wolfgang Reszel commentedHi,
can you post the whole preprocess_node function?
And how to access the view in node.tpl when not using print $content;?
Tekl
Comment #2
Funkymoses commentedWhat file does this go in?
Comment #3
Funkymoses commentedA: your template's template.php file.
Comment #4
OnlineWD™ commentedAnd 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.
Comment #5
hefox commentedAll 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:
and in the node template files at
Comment #6
eaton commentedAt 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.