Re: [SMARTY] section loop keys / nested loops

From: Date: Wed, 09 Apr 2003 20:45:25 +0000
Subject: Re: [SMARTY] section loop keys / nested loops
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9198@lists.php.net to get a copy of this message
My current preferred solution is to just stuff everything into the one array. In your case, just stuff the contacts into the offices array. Something like: # for each office, build contacts: $contacts['contact_id']['contact_name'] $contacts['contact_id']['contact_phone'] $offices['id'] $offices['city'] $offices['state'] $offices['id']['contacts'] = $contacts Then, in your template: {section name=office loop=$offices} {$offices[office].city}, {$offices[office].state}<br>
    {assign var="contacts" value=$offices[office].contacts}
    {section name=contact loop=$contacts}
    -- {$contacts[contact].name} <br>
    {/section}
{/section} cheers, Travis olinux wrote:
Hi all, Just starting smarty and love it so far. One trouble I have had is with nested loops. I am trying to use a piece of data from the outer loop to reference the inner array for this example OFFICES is the outer loop and CONTACTS the inner loop. each office may have multiple contacts. array format (maybe i should retrieve data differently?) $offices['id'] $offices['city'] $offices['state'] ... $contacts['office_id']['contact_id']['contact_name'] $contacts['office_id']['contact_id']['contact_phone'] ... so i want to use the current office id to loop contacts for that office. I have tried every possible option i can think of. ideally something like this: {$contacts[office.id][contact].id} the loop: {section name=office loop=$offices} {$offices[office].city}, {$offices[office].state}<br>
    {section name=contact loop=$contacts}
    -- {$contacts[office.id][contact].name} <br>
    {/section}
{/section} thanks much, olinux __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com
-- Travis Low <mailto:travis@dawnstar.com> <http://www.dawnstar.com>

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