Re: loop

From: Date: Wed, 28 Mar 2001 09:32:02 +0000
Subject: Re: loop
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-468@lists.php.net to get a copy of this message
Hi, Ivo Jansch wrote: > Ok, I played a little with Smarty_Compiler.class.php, and in _parse_var, > I put the foreach($props) loop *in front* of the $foreach($sections) > loop. Ok, forget this. If you do this, then a simple loop like: $smarty->assign("list",Array(Array("name"=>"sjappie"),Array(Array("name"=>"flappie"))); {section name=mysection loop=$ylist} <br>Url: {$mysection/list.name} {/section} won't work anymore. The reason is an ambiguity in the template language. In the above case, you want {$mysection/yourbookmarks.url} to mean: Give me the "url" var, of the current item from yourbookmarks. ($yourbookmarks[$i]['url']) Whereas in the other case: $smarty->assign("list",Array("names"=>Array("sjappie","flappie","happie"))); {section name="sec1" loop=$list.names} <br>{$sec1/list.names} {/section} you want $sec1/list.names to mean: Give me the current item from list['names'] ($list['names'][$i]) The ambiguity is in the fact that you don't specify 'the current item of'. When saying {$sec1/list.name}, you would need a way to tell the compiler: - "list" is my looping data, and from each item in the loop, I want to display the "name" item. OR - "list.name" is my looping data, and I want to display each item in the loop. If we solve this, we could define *ANY* datastructure that you could possibly think of. Solutions I have been thinking about: - {section name="sec1" loop=$list.names}, where $list.names is not just the array on which you loop, but also the 'base' for your data. ($sec1/url) would then give the "url" item from the $list.names array. Additional pro: nested sections can loop on items from the same assign statement, which would allow you to build a complete tree in one assign statement. - Change the syntax a bit, perhaps {$sec1/@items.url} or something like that.. Greetings, Ivo -- Ivo Jansch <ivo@ibuildings.nl> ibuildings.nl BV - information technology http://www.ibuildings.nl

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