Re: [SMARTY] problem with {section} tag not recognizing array

From: Date: Wed, 18 Dec 2002 06:39:31 +0000
Subject: Re: [SMARTY] problem with {section} tag not recognizing array
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6867@lists.php.net to get a copy of this message
Sebastien, {section} is designed to work with arrays that are indexed from zero. In your original post: $test1 = array( 'name' => 'sebastien', 'sex' => 'male'); should instead be something like: $test1[] = array( 'name' => 'sebastien', 'sex' => 'male'); $test1[] = array( 'name' => 'joe', 'sex' => 'male'); $test1[] = array( 'name' => 'jane', 'sex' => 'female'); You can then: {section name=t loop=$test1} {$test1[1].name} {$test1[1].sex} <br> {/section} If you need to use an assosiative array, look at the {foreach} section of the smarty manual. Regards, Jason ----- Original Message ----- From: "D. Sebastien Taggart" <dlst@seblin.com> To: "Monte Ohrt" <monte@ispi.net> Cc: <smarty-general@lists.php.net> Sent: Wednesday, December 18, 2002 3:31 AM Subject: RE: [SMARTY] problem with {section} tag not recognizing array > Thanks, but that didn't do it; I still get blank output, and > $smarty.section.customer.show is still false. Does "customer" have to be an > index in the array? > > > > -----Original Message----- > From: Monte Ohrt [mailto:monte@ispi.net] > Sent: Tuesday, December 17, 2002 10:15 PM > To: D. Sebastien Taggart > Cc: smarty-general@lists.php.net > Subject: Re: [SMARTY] problem with {section} tag not recognizing array > > > {section name=customer loop=$test1} > <tr> > <td>{$test1[customer]}</td> > </tr> > {/section} > > > D. Sebastien Taggart wrote: > > >Hi everyone, > > > >I'm having what I'm sure must be a simple problem with {section} tags: > > > >What's happening is that the {section} doesn't repeat, as if the array is > >empty, so I tried setting up a really simple sample, but it still behaves > as > >if the array is empty: > > > >from the php file: > > > >$test1 = array( 'name' => 'sebastien', 'sex' => > >'male'); > > > >from the template file: > > > > {section name=customer loop=$test1} > > <tr> > > <td>{$test1[0]}</td> > > <td>{$test1[1]}</td> > > </tr> > > {/section} > > > >I've tried several different arrays, including: > > > >$test2 = array( 1 => array ( 'name' => 'sebastien', > >'sex' => 'male' ), > > 2 => array ( 'name' => 'jenny', 'sex' => > > 'female' ) ); > > > >(Does the array need to be multi-dimensional?) > > > >What if I simply wanted a way to have the section repeat for a certain > >(known) number of times, like while( $row = mysql_fetch_array( > >$something ) )? I tried assigning an array with the same number of values, > >even an array with one number value, but to no avail. > > > >The manual does not supply the "sample array" ($custid) used in all the > >examples (http://smarty.php.net/manual/en/language.function.section.html), > >so it made it a little hard for me to figure out what was going on. Maybe > >that could be added in later for us beginners :). > > > >Thanks in advance for any light you could shed on this. > > > >-Sebastien > > > > > > > > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

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