Nested loops

Author Message

sergey podlesnyi

Thursday 23 January 2003 4:36:50 am

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,"/")|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.

Tony Wood

Thursday 23 January 2003 5:05:58 am

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,"/")|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.

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Alexei Pechekhonov

Saturday 25 January 2003 5:18:41 am

> {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

sergey podlesnyi

Monday 27 January 2003 8:56:09 am

> Try to use this code:
> {section name=Folder loop=$folder_list}
> <a
> href={concat("content/view/full/",$Folder:item.node_id,"/")|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!

Volker Lenz

Thursday 30 January 2003 1:27:55 pm

> > Try to use this code:
> > {section name=Folder loop=$folder_list}
> > <a
> >
> href={concat("content/view/full/",$Folder:item.node_id,"/")|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}

Matthew Rat

Thursday 10 April 2003 6:54:46 am

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?

Bård Farstad

Thursday 10 April 2003 8:01:19 am

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

Documentation: http://ez.no/doc

Mr Win

Thursday 24 April 2003 9:46:57 am

Yeah !!! working.

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.