Re: [SMARTY] Newbie Question: Associative Arrays and Sections

Patrick Ben Koetter <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <[email protected]>
WOW! That was quick! Thank you guys!

p@rick


* v3rb0 <[email protected]>:
> instead of section use foreach 
> 
> {foreach from=$customers item="customer" key="nick" name="custloop"}
> 	{$nick}:
> 	{$customer.lastname}
> 	{$customer.firstname}
> 	<hr />
> {/foreach}
> 
> -- 
> v3rb0
> 
> 
> 
> 
> On 04/07/05, Patrick Ben Koetter <[email protected]> wrote:
> > Hello everybody,
> > 
> > I know it has been described in the Smarty manual and in the mailing list
> > archives, but still I cannot access data in an nested array.
> > 
> > Here's what I have in my array of customers. Each customer itself is an array
> > with customer data:
> > 
> > $smarty->assign('customers',
> >   array(
> >     'john' => array(
> >       'lastname' => 'miller',
> >       'firstname' => 'john'
> >       ),
> >     'bob' => array(
> >       'lastname' => 'hope',
> >       'firstname' => 'bob'
> >       ),
> >     )
> >   );
> > 
> > AFAIK I can use {section} to loop through the first array and pick the data
> > from the nested arrays like this:
> > 
> > {section name=customer loop=$customers}
> >     <p>
> >     {$smarty.section.customer.index}<br />
> >     firstname: {$customers[customer].firstname}<br />
> >     lastname: {$customers[customer].lastname}
> >     </p>
> > {/section}
> > 
> > However I am unable to get this working. What I get is:
> > 
> > 0
> > firstname:
> > lastname:
> > 
> > 1
> > firstname:
> > lastname:
> > 
> > And the output in my error log is:
> > 
> > [client 172.16.0.1] PHP Notice:  Undefined offset:  0 in /srv/www/smarty/templates_c/%%6D^6D7^6D7C5625%%test.tpl.php on line 34
> > [client 172.16.0.1] PHP Notice:  Undefined offset:  0 in /srv/www/smarty/templates_c/%%6D^6D7^6D7C5625%%test.tpl.php on line 36
> > [client 172.16.0.1] PHP Notice:  Undefined offset:  1 in /srv/www/smarty/templates_c/%%6D^6D7^6D7C5625%%test.tpl.php on line 34
> > [client 172.16.0.1] PHP Notice:  Undefined offset:  1 in /srv/www/smarty/templates_c/%%6D^6D7^6D7C5625%%test.tpl.php on line 36
> > 
> > I'd really apprechiate if someone took the time and helped me fix this or even
> > understand what I am doing wrong her.
> > 
> > Thanks!
> > 
> > p@rick
> > 
> > --
> > Smarty General Mailing List (http://smarty.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> >

-- 
state of mind
Agentur für Kommunikation und Design

Patrick Koetter            Tel: 089 45227227
Echinger Strasse 3         Fax: 089 45227226
85386 Eching               Web: http://www.state-of-mind.de

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.