Re: [SMARTY] Testing for counter value
| From: | Martin Braun | Date: | Tue, 13 Jul 2004 18:35:32 +0000 |
| Subject: | Re: [SMARTY] Testing for counter value | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11581@lists.php.net to get a copy of this message | ||
Sarah Gray wrote:
What's the syntax for testing if {counter}is at a certain value? I started a counter in a foreach loop and it increments and is reset periodically and I want to be able to say {if counter == 2} // do something {/if} Anyway, nothing happens, it's like the if statement isn't seen. [also tried {if $counter==2} and {if {counter} == 2}] Is this possible?sure! first of all, if you only want to count the number of iterations, you can use $smarty.foreach.foreachname.iteration (see http://smarty.php.net/manual/en/language.function.foreach.php), say if you want to do something every n-th iteration. if you are using an extra counter variable for any reason you might have (having something like {assign var="counter" value="
$counter+1"} in every iteration) doing
{if $counter == 2} ...code...{/if}
should work fine.
just check the manual, sections 'basic syntax' and 'math'.
martin
--
/* no comment */
Please use my public PGP key: http://www.mbant.de/mbant-gpg-key