Skip to main content

Some nice quick views theming tricks in Drupal 5

An article from ComputerMinds - Building with Drupal in the UK since 2005
27th Jan 2009

Mike Dixon

Senior Mind
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

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

function phptemplate_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
  static $count;

foreach ($nodes as $n) { $node = node_load($n->nid); $node->view_name = $view->name; $node->position_in_view=$count[$view->name];

$count[$view->name]+=1;
$output .= node_view($node, $teasers, false, $links);

}
return $output;
}

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.