I want to create foreach smarty loop with counter and 3 "if" conditions inside. After my counter value is greater than 3, I want to reset the counter value and return to the first condition If
This is my code.
{foreach $itemscollection as $singleitem name=smartyloop}
{assign var="counter" value=$smarty.foreach.smartyloop.iteration}
{if $counter == 1}
<h1>I am the one</h1>
{/if}
{if $counter == 2}
<h1>I am second</h1>
{/if}
{if $counter == 3}
<h1>I am third</h1>
{/if}
{if $counter > 3}
{$counter = 1}
{/if]
{/foreach}
So, for example, if I have 4 elements to place in foreach, the output should look like
I am the one
I am second
I am third
I am the one
Now it does not work, and I do not know why. Can someone please help me and tell me how to solve this problem?
source
share