Passing $view information into $node?
Fiasst - August 25, 2008 - 12:23
Hi, I'm looking to make the $view->name available in the Views child $nodes.
So, for example; in my node.tpl file I can print the name of the $view that the node is contained within. Is this at all possible?
Thanks for reading.

You can add this to your
You can add this to your themes template.php file
function phptemplate_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {foreach ($nodes as $n) {
$node = node_load($n->nid);
$node->view = $view;
$output .= node_view($node, $teasers, false, $links);
}
return $output;
}
and then you can use $node->view->name in node.tpl.php to print the name of the view. Note this is a generic theme override for views that generate a list of nodes, if you override a specific view you will need that function to do
$node->view = $view;after calling node_load().Your a bloody genius! I could kiss you..
I've just tested this and it's opened up theming to a new dimension!
I can now add multiple node teaser layouts for the same content type, on the same page depending on the View they are embedded within.
I've been searching for a way to do this for months :]
Thanks nevets
I almost get it
sorry ...
trying to find a similar solution ... and this seems to be the work flow ..
but I don't quite get how to take control of the printing and css styling within the node.tpl.php at present I've got this ...
<?php if ($node->view->name == 'articles') { ?><h1 class="title"><?php print $node_view; ?></h1>
<?php } ?>
I want to test to see what view name is and style the view accordingly .... I tried inserting $node_load in node.tpl.php and the site crashed .. presumably that's the wrong approach .....
I know I'm missing the point somewhere ... ???
and I know that three or four of the right words from you guys could open all the right doors ....
fingers crossed
My solution requires placing
My solution requires placing the above function in your themes template.php file at which point $node->view should be available in node.tpl.php when the node is viewed through a view that lists nodes (full or teaser).
And a side note, calling node_load in node.tpl.php on the node be displayed causes "infinite" recursion (or at least till it crashes).
correct method for testing node view settings
ah I see
I was using the code inserted into template.php ... I think where I've gone wrong is in the way I test for node->view
what is the correct syntax?
please forgive my extreme ignorance
nooB disclaimer - "Folks are Dumb where I come from"
It looks right though I
It looks right though I always forget if view is an object or array. You could add
<pre><?php print print_r($node->view, TRUE); ?>
</pre>
to the end of your node.tpl.php file to check that and also make sure you have the correct field name.
thanks for the tips ... I've
thanks for the tips ...
I've abandoned this approach for the moment ... although I tried it and got something about object not being able to convert to string ...
I'm currently testing the views/panels potential in D6.4 .. and off the bat It's a lot better although there seems to be some bugs occurring ... not sure if it's me or the panels mod ... keep testing I s'pose
but thanks for responding, appreciate it ...
Hi azabug, Here's how I
Hi azabug,
Here's how I check which View is present along with other node checks:
<?phpif ($node->type == 'news'):
if ($node->view->name == 'latest_news'){
//view layout
} else {
if ($page == 1){
//teaser layout
} else {
//full page layout
}
}
elseif ($node->type == 'video'):
//repeat steps..
endif;
?>
Hope that helps
cheers
Hey thanks for that Fiasst ...
I'll check it out ... I see my error was in trying to print it .. when all I needed do was set the css styles ... very cool ...
I'll let you know how it goes
thanx