Re: [SMARTY] looping foreach
| From: | Jordi Canals | Date: | Wed, 17 Nov 2004 15:50:37 +0000 |
| Subject: | Re: [SMARTY] looping foreach | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11974@lists.php.net to get a copy of this message | ||
Hi,
Comments inline...
On Wed, 17 Nov 2004 15:15:02 +0100, Rainer Bendig aka Ny
<lists@unresolvedissue.org> wrote:
> the array is sorted via mysql statement - will smarty keep the sorting or should i sort it via
> template (if, how?)
Smarty will keep your sorting. Yo have not to sort it in the template
> the array should be used to build an menu aka this sample:
>
> ArrayID 0 ($item.c=m)
> |- ArrayID 1 ($item.c=s)
>
> ArrayID 2 ($item.c=m)
> |- ArrayID 3 ($item.c=s)
In that case I would use a multidimensional array similar to that sample:
menu
[0]
[text] = your text here
[link] = your link here (If there is one)
[items] (array)
[0]
[text] = your menu text
[link] = you link here
[1]
[text] = your menu text
[link] = you link here
[1]
[text] = your text here
[link] = your link here (If there is one)
[items] (array)
[0]
[text] = your menu text
[link] = you link here
[1]
[text] = your menu text
[link] = you link here
Here you have the array formated as you will use it in your menu
Just now, you can use the {foreach}
{foreach name=main from=$menu item=entry}
<a href="{$entry.link}">{$entry.text}</a>
{foreach name=submenu from=$entry.items item=subentry}
<a href="{$subentry.link}">{$subentry.text}</a>
{/foreach}
{/foreach}
Note that the code is untested, but hope could give you some help.
Best regards,
Jordi.