Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Multiple cycles inside a loop - Fix by naming them - Easier!

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Sat Mar 14, 2009 5:37 am    Post subject: Multiple cycles inside a loop - Fix by naming them - Easier! Reply with quote

Normally, multiple use of {cycle}s inside a loop do not work.
If you use two different cycles in a loop, the earlier one is executed only once. An example that is buggy is:
Code:
{foreach from=$vote_statistics key=key item=item name="f_e"}
{cycle values="8888FF,FF00FF,3399FF,FF8800,0000FF,004701,EEFF33,9B0202" assign="graph_color"}
<p style="padding:0; margin:3px;"><span style="color:#{$graph_color}">
   {cycle values="A,B,C,D,E,F,G,H,I,J,K"}.
   {$item.text}</span>: {$item.points|escape}%</p>
{/foreach}

And the solved things are:
{foreach from=$vote_statistics key=key item=item name="f_e"}
Code:
{cycle values="8888FF,FF00FF,3399FF,FF8800,0000FF,004701,EEFF33,9B0202" name='chart_color' assign="graph_color"}
<p style="padding:0; margin:3px;"><span style="color:#{$graph_color}">
   {cycle values="A,B,C,D,E,F,G,H,I,J,K" name='chart_alphabet'}.
   {$item.text}</span>: {$item.points|escape}%</p>
{/foreach}


Explanation:
Give names to each of the cycles even if you do not use these names. By naming cycles; Smarty assumes them to be really different; and cycles through then in every {foreach} loop.

Notice these pieces:
... name='chart_color' ...
... name='chart_alphabet' ...


Does this help somebody? I think, it worked great to me.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP