New macro cycle from smarty
Notice: This thread is very old.
- Felix
- Nette Core | 1245
I have wondering about new macro {cycle ..}, idea taken from smarty:cycle.
Use case (3 records):
{foreach $rows as $row}
<a class="label {cycle label-info, label-success, label-error}" n:href="..">{$row->a}</a>
{/foreach}
Output:
<a class="label label-info" href="..">a</a>
<a class="label label-success" href="..">b</a>
<a class="label label-error" href="..">c</a>
Implementation (CoreMacros):
$me->addMacro('cycle', '$_cycle = %node.array; echo $_cycle[$iterator->counter%count($_cycle)];');
What do you think guys? Is it useless or it could helps?
- David Grudl
- Nette Core | 8228
Correction:
{foreach $rows as $row}
<a n:class="label, [label-info, label-success, label-error][$iterator->counter % 3]" n:href="..">
{$row->a}
</a>
{/foreach}