I am not usually a Smarty guy, so I’m a bit stuck.
I want to echo the index of an array, but I want to increment it each time I echo it.
This is what I have…
<ul>
{foreach from=$gallery key=index item=image}
<li>
<img src="{$image}" alt="" id="panel-{$index++}" />
</li>
{/foreach}
</ul>
It doesn’t work.
Is the best way to do this to pre-process the array before handing it to Smarty?
Is there a way I can do this using Smarty?
You can do something like the following:
Starting from zero,
indexis the current array index.That’s probably the best way to go about it, however, to simply use a counter outside of a
foreachloop you can usecounter, like so:To increment it simply call
{counter}at each iteration.