Re: Unlimited nested sections
| From: | Linus McCabe | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: Unlimited nested sections | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2581@lists.php.net to get a copy of this message | ||
Fill your array with all category levels, something like this:
$cats[0]['name'] = 'Category 1'
$cats[0]['level'] = 1
$cats[0]['id'] = 12
$cats[1]['name'] = 'Category 1a'
$cats[1]['level'] = 2
$cats[1]['id'] = 18
$cats[2]['name'] = 'Category 1b'
$cats[2]['level'] = 2
$cats[2]['id'] = 22
$cats[3]['name'] = 'Category 1b(i)'
$cats[3]['level'] = 3
$cats[3]['id'] = 42
$cats[4]['name'] = 'Category 2'
$cats[4]['level'] = 1
$cats[4]['id'] = 43
(in reality this might be a recursive function, or somthing similar)
Then loop something like:
{section name=cat loop=$cats}
<div style="margin-left: {$cats[cat].level}cm">
{$cats[cat].name}
</div>
{/section}
/linus
On Sat, 26 Jan 2002 15:36:54 -0500 Brad Atkins <brad@youreshop.com> wrote:
> Hello,
>
> We have the following situation which is causing us lots of headaches,
> and hope that someone can help us.
>
> In our application we want the ability to display an unlimited number of
> categories and they can be nested within each. An example would be:
>
> Category 1
> ---Category 1a
> ------Category 1a(i)
> Category 2
>
> This means that Category 1 has a sub category called Category 1a, and
> Category 1a has a sub category called Category 1a(i), and this can
> continue to any depths.
>
> We were initially using the {section} loops, however, we would have to
> embed them within each other, and this gets messy.
>
> Is there some automated way to loop through these without having to
> embed sections upon sections upon sections?
>
> Any help or ideas would be greatly appreciated!
>
> Thanks,
> Brad
>
>
> ---
> You are currently subscribed to smarty as: linus@mccabe.nu
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at �oì?¾Ì"EÔ5
Y˜
> z€http://www.phpinsider.com/php/code/Smarty/
>