Re: [SMARTY] Help : section & loop

From: Date: Thu, 09 Sep 2004 12:23:15 +0000
Subject: Re: [SMARTY] Help : section & loop
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11782@lists.php.net to get a copy of this message
You cant loop over an associative array with section, use foreach: {foreach from=$my_array key="key" item="var"} <tr class="{cycle values="TabLigne1,TabLigne2"}"> <td height="21" >{$key}</td> <td >{$var.prenom}</td> <td >{$var.adresse}</td> </tr> {/foreach} Foreach is also ALWAYS easier to use than section, so unless you have a specific need for a loop that is counted (ie for() ) then you're better off using foreach. http://smarty.php.net/manual/en/language.function.foreach.php -bok On Thu, 9 Sep 2004 14:13:51 +0200, Toorop <toorop@cyborgnation.org> wrote: > Hi, > > I didn't find how to do a template : > > My array : > > $my_array=Array > ( > [dupont] => Array > ( > [id] => 38 > [prenom] => titi > [adresse] => DupontTown > . > . > . > ) > > [martin] => Array > ( > [id] => 43 > [prenom] => toto > [adresse] => MartinTown > . > . > . > ) > > ) > > I want a output like : > > dupont | titi | DupondTown > martin | toto | MartinTown > > But i find anything working :/ > > My *not working* template : > > {section name=num_loop loop=$my_array} > <tr class="{cycle values="TabLigne1,TabLigne2"}"> > <td height="21" >{i really don't know how to show tab key, ie > dupont for the first loop}</td> > <td >{$mon_tableau[num_loop].prenom}</td> // Not working show nothing > <td >{$mon_tableau[num_loop].adresse}</td> // Not working show nothing > . > . > . > </tr> > {/section} > > Escuse my poor english, i hope you understand my problem, Thx ;-) > > -- > Toorop > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.smarty.general (#11782) next »