Counter inside iterate smarty loop

hd. picture hd. · Oct 22, 2011 · Viewed 12.9k times · Source

I have this smarty code :

{iterate from=fruits item=fruit}
 ....
{/iterate}

I want to have a counter inside this loop that accept a start value and increase by one until the loop continues.

I should i use? i am not good in smarty.

Thank you.

Answer

Book Of Zeus picture Book Of Zeus · Oct 22, 2011

You can use the .iteration

{foreach from=fruits item=fruit}
 current item #: {$smarty.foreach.fruits.iteration}
{/foreach}

source: http://www.smarty.net/docsv2/en/language.function.foreach.tpl#foreach.property.index