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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
haapati
Forum Members
Forum Members
Posts: 20
Joined: Sun Sep 10, 2006 4:14 pm

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

Post 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?
Last edited by haapati on Fri Dec 17, 2010 11:14 am, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm

Re: How to create a smarty variable what counts foreach

Post 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}
haapati
Forum Members
Forum Members
Posts: 20
Joined: Sun Sep 10, 2006 4:14 pm

Re: How to create a smarty variable what counts foreach

Post by haapati »

Thanks. It works fine.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

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

Post by Wishbone »

You could also do:

Code: Select all

Picture {$i++}
Post Reply

Return to “CMSMS Core”