Re: [SMARTY] Testing for counter value
| From: | Sarah Gray | Date: | Tue, 13 Jul 2004 19:07:30 +0000 |
| Subject: | Re: [SMARTY] Testing for counter value | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11583@lists.php.net to get a copy of this message | ||
Thanks to both of you! Assigning the counter to a variable was what I needed.
I am also using $smarty.foreach.foreachname.iteration -- but it's a complex
layout that needs a second
counter as well. ;)
s.
messju mohr wrote:
> On Tue, Jul 13, 2004 at 08:35:32PM +0200, Martin Braun wrote:
> > 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
>
> just for the records: the "..." are redundant here.
> {assign var="counter" value=$counter+1} should do.
>
> another way would be {counter assign=i ...} and use {$i} afterwards.
>
> IMHO the nicest is the first one martin mentionend: give the foreach a
> name and use {$smarty.foreach.[name].iteration} or maybe
> {$smarty.foreach.[name].iteration+$offset}.
>
> > {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
> >
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php