Skip to main content
ComputerMinds

Some nice quick views theming tricks in Drupal 5

Thought I would post this little function on here, we tend to use it a lot and it gives some nice little extras for you to play with when you come to template your nodes.

Mike DixonSenior Mind · · 1 min read

Thought I would post this little function on here, we tend to use it a lot and it gives some nice little extras for you to play with when you come to template your nodes.

  • $node->view_name : the name of the view this node is being rendered in
  • $node->position_in_view : the position within the view for this node
<code class="language-php hljs">
function phptemplate_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
  static $count;
<p>foreach ($nodes as $n) {
$node = node_load($n->nid);
$node->view_name = $view->name;
$node->position_in_view=$count[$view->name];</p>
<pre><code>$count[$view->name]+=1;
$output .= node_view($node, $teasers, false, $links);
</code>

}
return $output;
}

Written by

Mike Dixon, Senior Mind

Meet the team