This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Install & configuration » Nested loops
expandshrink

Nested loops

Nested loops

Thursday 23 January 2003 1:36:50 pm - 7 replies

Are nested loops possible? If so, could you help me find reason why the following code is not working:

{section name=Folder loop=$folder_list}
<a href={concat("content/view/full/",$Folder:item.node_id,"/"blunk.gif Emoticon|ezurl}>{$Folder:item.name}</A>
<UL>
{section name=sub loop=$subfolder_list}
<LI><a href=#>{$sub:item.name}</a>
{/section}
</UL>
{/section}

Here $folder_list and $subfolder_list are valid arrays built by fetch; I can print them out separately without problems but when I nest it one into another they fail. Interesting, $subfolder_list still has correct number of elements, I can see it by bullets printed by <UL>. But real data (name) is lost.

I need a solutin because I want to build left-hand menu on site where top level menu entries are dynamically built from folders on root level (variable: $folder_list) and second-level menu is built from folders located inside root level folders.

Thursday 23 January 2003 2:05:58 pm

I tried to use nested loops, but i found the loops worked but the values were not being returned correctly, so gave up till full version comes out... It may be a bug..

> Are nested loops possible? If so, could you help me find
> reason why the following code is not working:
>
> {section name=Folder loop=$folder_list}
> <a
> href={concat("content/view/full/",$Folder:item.node_id,"/"blunk.gif Emoticon|ezurl}>{$Folder:item.name}</a>
> <UL>
> {section name=sub loop=$subfolder_list}
> <LI><a href=#>{$sub:item.name}</a>
> {/section}
> </ul>
> {/section}
>
> Here $folder_list and $subfolder_list are valid arrays
> built by fetch; I can print them out separately without
> problems but when I nest it one into another they fail.
> Interesting, $subfolder_list still has correct number of
> elements, I can see it by bullets printed by <UL>. But real
> data (name) is lost.
>
> I need a solutin because I want to build left-hand menu on
> site where top level menu entries are dynamically built from
> folders on root level (variable: $folder_list) and
> second-level menu is built from folders located inside root
> level folders.

Saturday 25 January 2003 2:18:41 pm

> {section name=sub loop=$subfolder_list}
> <LI><a href=#>{$sub:item.name}</a>
> {/section}

Try the following (do remember name spaces)
{section name=sub loop=$subfolder_list}
<LI><a href=#>{$Folder:sub.item.name}</a>
{/section}
Alexei
alpexjava @ bigpond.com

Monday 27 January 2003 5:56:09 pm

> Try to use this code:
> {section name=Folder loop=$folder_list}
> <a
> href={concat("content/view/full/",$Folder:item.node_id,"/"blunk.gif Emoticon|ezurl}>{$Folder:item.name}</A>
>
> <UL>
> {section loop=$subfolder_list}
> <LI><a href=#>{$Folder:item.name}</a>
> {/section}
> </UL>
> {/section}
> -----------

Thank you Sergey: tested - it worked!

Thursday 30 January 2003 10:27:55 pm

> > Try to use this code:
> > {section name=Folder loop=$folder_list}
> > <a
> >
> href={concat("content/view/full/",$Folder:item.node_id,"/"blunk.gif Emoticon|ezurl}>{$Folder:item.name}</A>
> >
> > <UL>
> > {section loop=$subfolder_list}
> > <LI><a href=#>{$Folder:item.name}</a>
> > {/section}
> > </UL>
> > {/section}
> > -----------
>

This one should do the job, too -- if you have reasons to seperate namespaces in more complicated situations:
{section name=Folder loop=$folder_list}
<a href={concat("content/view/full/",$Folder:item.node_id,"/"|ezurl}>{$Folder:item.name}</a>

<ul>
{section name=SubFolder loop=$subfolder_list}
<li><a href=#>{$Folder:$SubFolder:item.name}</a></li>
{/section}
</ul>
{/section}

Thursday 10 April 2003 3:54:46 pm

I am having a problem with this too and I have read through the replies but still cannot seem to get this to work. One thing I did NOT see is LET statements that FETCH the content based on the NODE_ID of the primary section. Take:

{let folder_list=fetch(content,list,hash(parent_node_id,240,sort_by,array(array(priority))))}
{section name=Folder loop=$folder_list}
{let subfolder_list=fetch(content,list,hash(parent_node_id,$Folder:item.node_id,sort_by,array(array(priority))))}
<a href={concat("content/view/full/",$Folder:item.node_id,"/"|ezurl}>{$Folder:item.name}</a>
<ul>
{section name=SubFolder loop=$subfolder_list}
<li><a href=#>{$Folder:$SubFolder:item.name}</a></li>
{/section}
</ul>
{/section}

Even when I hardcode a value for the 2nd fetch's "parent_node_id", I get nothing and there are 5 folders in there. If I take the 2nd SECTION (including LET) and put it outside the loop, hardcode the node_id, and remove the "$Folder:" prefix from the line, THEN I get some results. Am I doing something wrong with my LET statements or something?

Thursday 10 April 2003 5:01:19 pm

The problem seems to be with namespaces. This is an example that works: Notice the $Folder:sub_folder_list.

{let folder_list=fetch(content,list,hash(parent_node_id,2,sort_by,array(array(priority))))}

{section name=Folder loop=$folder_list}
<b>{$Folder:item.name}</b>:<br />
{let sub_folder_list=fetch(content,list,hash(parent_node_id,$Folder:item.node_id,sort_by,array(array(priority))))}

{section name=SubFolder loop=$Folder:sub_folder_list}
-{$Folder:SubFolder:item.name}<br />
{/section}

{/let}
{/section}

{/let}

--bård

Thursday 24 April 2003 6:46:57 pm

Yeah !!! working.

But if I want to listing only "subfolder" under "folder", not all item
or listing all article with out folder.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from