I am trying to simple access a counter for each node that gets displayed in contemplate. Is there a simple way to do this?

I created a variable in template.php which I can access in node.tpl.php, but not in contemplate. For each node displayed, I need to iterate a counter variable and display it.

I have been trying to figure out how to get this to work in contemplate for an hour now with no luck. I HAVE to just be doing something stupid or missing something simple. Can someone help me?

Thanks,
Sunsu

Comments

jrglasgow’s picture

Status: Active » Postponed (maintainer needs more info)

a simple way to do it would be by using the variable_get() and variable_set() functions.

here is an example:

$count = variable_get('custom_contemplate_counter', 1); //get the count variable from Drupal's variables table, if the variable is not already set we use the default of 1
print 'count: '. $count ; // print out the count
variable_set('custom_contemplate_counter', $count + 1); // increment the count and save to the variables table

Will this work for you?