Re: [SMARTY] looping foreach
| From: | Jochem Maas | Date: | Wed, 17 Nov 2004 15:40:41 +0000 |
| Subject: | Re: [SMARTY] looping foreach | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11973@lists.php.net to get a copy of this message | ||
Rainer Bendig aka Ny wrote:
Hi, i've got the fallowing issue: Array (4) 0 => Array (6) a => empty b => Ausgangsstelle c => m d => 0 e => 1 f => empty 1 => Array (6) a => index b => Start c => s d => 1 e => 2 f => empty 2 => Array (6) a => s2 b => sub2 c => s d => 3 e => 4 f => empty 3 => Array (6) a => empty b => Cat2 c => m d => 0 e => 3 f => empty $array.a is a link its converted via template to {$array.a}.html $array.b is simple text $array.c is the role of the entry m for master and s for slave $array.d is the value of $item.e if $item.c is "s" and stands for the main category $array.e is the id of the mysql entry $array.f is unused until now, and will become "show on sitemap" or something else) the array is sorted via mysql statement - will smarty keep the sorting or should i sort it via template (if, how?)smarty won't do anything to the order of your array (although there are probably numerous ways to get it to do that if you explicitly want it to).
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)
I tried to build it via the fallowing sample of the wiki ($navm is my array name)
{foreach name=outer item=navm from=$navm}
could be going wrong because the item var and the from var have the same name ('navm').
e.g change it to:
{foreach name=outer item=navmItem from=$navm}
{foreach name=inner key=key item=item from=$navmItem}
<div id="l4navpoint">{$key.b}}</div>
{/foreach}
....
you may be trying to achieve something with recursion here, if thats the case then it will not work in its current form (I would suggest having a look at the include plugin as one way of handling this recursion)
{foreach name=inner key=key item=item from=$navm}
<div id="l4navpoint">{$key.b}}</div>
{/foreach} {foreach key=key item=item from=$navm }
<div id="l4subnav">
<span class="bold">»</span> {$item.b} </div>
{/foreach}
{/foreach}
I also tried to work with two arrays (seprated master and slave) but didn't get it to work, because i dont know how to filter the array in the template, and i also think its to slow
thx in advice
rainer
(This is my first post to the list, if i should turn off gpgsigning, please tell)
don't know anything about that sorry ;-)