I have a simple view, that displays nodes using a style of unformatted and a row style of node.

I am using a variant of a node.tpl.php to style each node. My issue is that I need to know which node I am working on in the list. If views returns 10 nodes, I need to know which node is where in the list. At the node.tpl.php level, I can't find a var that tells me that, nor can I see a place to set it and have it fall down like in views-view-unformatted.tpl.php, there in the loop, I could create the count var, but I can't pass it to the node.tpl.php as the row object there is already themed.

Comments

drupalnuts’s picture

Title: node list get location » node list number of node in list for theme layer
nevets’s picture

This might help, at the top of node.tpl.php try adding

//  Make sure called as  part of a view
if ( !empty($node->view) )  {
   if  ( empty($node->view->node_counter)   )  {
      //  First node,  initialize the  counter
      $node->view->node_counter  = 1;
   }
   $counter  =  $node->view->node_counter++;
}
drupalnuts’s picture

Component: node data » Documentation

Oh that is very cool.

On the themeing information for the views, it should state some place that the $view object is there to be used.

ygerasimov’s picture

That works great! but what if we have pager? this method gives numbers only of the page. how to get the page number (i think it can be done from url of the page) and number of the nodes on the page?

thank you in advance.

dawehner’s picture

There is a field Global: counter, which does exact this.

I think you can use this.

davedg629’s picture

Yes there is the field Global: result counter, but that field is only available when creating a field View. If you are using a node view then you have to do this at the theme level somewhere. Anyone have a solution to #4?

dawehner’s picture

Status: Active » Fixed

You can get the page number by $view->get_current_page();

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.