PDA

View Full Version : Counters within a template?


Trana
09-21-2008, 02:39 PM
Is there any way to put a global variable into a template (like postbit or threadbit) so that I can modify the output with conditionals once criteria is met?

For example, a simple counter count++ placed in a template so that it increases every time the template is loaded on a page, and if the count gets to a certain number I can make a change to the output with an <if>?

I don't know if this can be done in a template without using a plugin or file change.

Thanks!

Dismounted
09-22-2008, 05:35 AM
<if condition="++$count == 10">We've reached 10!</if>

Trana
09-23-2008, 11:30 PM
Do I need to initialize it or anything?

Dismounted
09-24-2008, 04:46 AM
No. As long as $count has not been used - it will be empty, or "zero". If you want to initialise it first, you can do this (bit messy though):
<if condition="!isset($count)"><if condition="$count = 0"></if></if><if condition="++$count == 10">We've reached 10!</if>

Trana
09-27-2008, 01:53 AM
Can you tell me how to do an OR with that same construct? I can't seem to get it to work.

Thanks!

Dismounted
09-27-2008, 04:42 AM
<if condition="$condition1 == true OR $condition2 == true">Either condition 1 or 2 is true.</if>

Trana
09-27-2008, 11:48 AM
Do I put the ++ on one of the variables or both of them?

Dismounted
09-27-2008, 01:39 PM
What exactly do you want to do? "++" means increment.

Trana
09-28-2008, 03:09 AM
I know, I just didn't understand if I am using multiple conditionals if I needed to put the ++ in both conditions.

I think I have it now, thanks!