Page 1 of 1

[solved] How to create a smarty variable what counts foreach

Posted: Fri Dec 17, 2010 10:56 am
by haapati
I have code

Code: Select all

{foreach from=$children item='child'}
{$i++}

Picture {$i}

{/foreach}
Output is

Code: Select all

1
Picture 1
2
Picture 2
3
Picture 3
Output what I want to

Code: Select all

Picture 1
Picture 2
Picture 3
How?

Re: How to create a smarty variable what counts foreach

Posted: Fri Dec 17, 2010 11:08 am
by Jos
looked up from http://www.smarty.net/docsv2/en/languag ... oreach.tpl
{foreach from=$children item='child' name=foo}

Picture {$smarty.foreach.foo.iteration}

{/foreach}

Re: How to create a smarty variable what counts foreach

Posted: Fri Dec 17, 2010 11:14 am
by haapati
Thanks. It works fine.

Re: [solved] How to create a smarty variable what counts foreach

Posted: Fri Dec 17, 2010 3:10 pm
by Wishbone
You could also do:

Code: Select all

Picture {$i++}