Re: [SMARTY] section loop keys / nested loops
| From: | olinux | Date: | Wed, 09 Apr 2003 21:03:00 +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-9199@lists.php.net to get a copy of this message | ||
seems like a good idea.
I guess the problem is that section works for indexed
arrays only. Maybe the manual should mention this.
What benefits does using section have over foreach?
(seems foreach would be more flexible since it can
take associative arrays)
I like the sectionelse syntax rather than combining
if/else
i.e.
{if $contacts != ""}
{foreach from=$contacts item=contact}
{$contact.name}
{/foreach}
{else}
No contacts
{/if}
Thanks to all who replied!
--- Travis Low <travis@dawnstar.com> wrote:
> 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
>
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com