RE: [SMARTY] problem with {section} tag not recognizing array
| From: | D. Sebastien Taggart | Date: | Wed, 18 Dec 2002 10:24:19 +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-6871@lists.php.net to get a copy of this message | ||
Jason,
May the road rise to meet you, and may the wind be always at your back. I
can't thank you enough for your persistence and help. You have ended two
days of frustration with one simple observation! Thanks again.
-Sebastien
-----Original Message-----
From: Jason Sweat [mailto:sweatjejm@mchsi.com]
Sent: Tuesday, December 17, 2002 11:05 PM
To: D. Sebastien Taggart
Cc: smarty-general@lists.php.net
Subject: Re: [SMARTY] problem with {section} tag not recognizing array
Sebastien,
In the php script did you do
$t->assign('test1',$test1);
before calling $t->display('template'); ?
I did mean the section version with $test1[t].
Jason
----- Original Message -----
From: "D. Sebastien Taggart" <dlst@seblin.com>
To: "Jason Sweat" <sweatjejm@mchsi.com>
Cc: <smarty-general@lists.php.net>
Sent: Wednesday, December 18, 2002 4:03 AM
Subject: RE: [SMARTY] problem with {section} tag not recognizing array
> Hi Jason,
>
> Thanks very much for your help, but the array simply refuses to display
> ($smarty.section.customer.show is still false). Instead of
>
> {section name=t loop=$test1}
> {$test1[1].name} {$test1[1].sex} <br>
> {/section}
>
> Did you mean:
>
> {section name=t loop=$test1}
> {$test1[t].name} {$test1[t].sex} <br>
> {/section}
>
> ?
>
> Either way, I get no ouput, even with a one-dimensional, zero-indexed
array
> such as:
>
> for ( $i = 1; $i <= 10; $i++ ) {
> $test3[] = $i * 23;
> }
>
> (So $test3 looks like this: Array ( [0] => 23 [1] => 46 [2] => 69 [3] =>
92
> [4] => 115 [5] => 138 [6] => 161 [7] => 184 [8] => 207 [9] => 230 )
>
> And:
>
> {section name=foo loop=$test3}
> {$test3[foo]} <br>
> {/section}
>
> ...still yields no data.
>
> I should have mentioned ealier, I tried dowloading the mysql.phps sample
> file at http://smarty.php.net/contribs/examples/mysql/ but my
> browser
claims
> the file contains no data. Does anyone have this or another simple
example
> I can use to clear this up (I'm sure I'm missing something simple).
>
> Thanks again.
>
> -----Original Message-----
> From: Jason Sweat [mailto:sweatjejm@mchsi.com]
> Sent: Tuesday, December 17, 2002 10:40 PM
> To: D. Sebastien Taggart
> Cc: smarty-general@lists.php.net
> Subject: Re: [SMARTY] problem with {section} tag not recognizing array
>
>
> 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
> >
> >
>
>
> --
> 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