agente_secreto
agente_secreto

Reputation: 8079

PHP for Drupal Views theming

I am theming a View in Drupal 6, and I want to add an id with a consecutive number to each item in the view (first item would have the id #item1, the second #item2, etc).

I am customizing the style output (views-view-unformatted--MYVIEWNAME.tpl.php) and the row style output (views-view-fields--MYVIEWNAME.tpl.php), and I want to add a counter variable in the foreach loop in the style output tpl, and then use that variable in the row style output tpl, but the last one is not recognizing the variable. It does not give me any errors, but doesnt print the number.

I understand this has probably something to do with variables visibility, how can I declare the counter variable in the style .tpl so I can the use it in the row style .tpl?

Upvotes: 1

Views: 493

Answers (1)

Kevin
Kevin

Reputation: 13226

Using a row based tpl,

$count = 0;

Then in your for/while loop looping results to print rows, something like:

<div id="row-<?php print $count;?>">
...code...
$count++;

That should do the trick, be sure to increment $count at the very end. I'm not sure if that will hold up on paged queries, though.

Upvotes: 1

Related Questions