bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Sat Mar 14, 2009 5:37 am Post subject: Multiple cycles inside a loop - Fix by naming them - Easier! |
|
|
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. |
|