Re: [SMARTY] recurse sections in smarty

From: Date: Wed, 17 Dec 2003 09:07:00 +0000
Subject: Re: [SMARTY] recurse sections in smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10713@lists.php.net to get a copy of this message
the only built-in way to do recursion in smarty is via include and that's not slow if you have deeply nested structures: [menu.tpl] <ul> {foreach from=$menu item=elem} <li> {if is_array($elem)} {include file="menu.tpl" menu=$elem} {else} {$elem} {/if} </li> {/foreach} </ul> i think you are best off restructuring your data to avoid recursion. On Tue, Dec 16, 2003 at 11:15:21PM +0100, Sims, Benjamin wrote: > Sorry to ask two questions in one day: > > I have an array, where the elements can either be an id, name pair or > another array containing id, name pairs (or more arrays). > > What I want Smarty to do is to > > - if the element is an id, name pair print it. > - if it is another array, indent and then foreach over it > > and so on. This should be recursive, so that if another array is reached it > is treated in the same way. > Am I asking too much from Smarty here? > > Just as an example, the data structure might be: > > Array( > > id2, name > id3, name > > Array( > id4, name > id5, name > Array( > id7,name > ) > ) > > id6, name > > ) //end array > > The output should be > > id2, name > id3, name > id4,name > id5,name > id7,name > id6,name > > > As you have probably guessed, its a menu. At the moment I am probably going > to completely redo the data structure (or maybe use an object) so if anybody > has any ideas I would be grateful. > > Benjamin Sims > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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