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.

eZ debug

Timing: Jan 30 2025 19:45:55
Script start
Timing: Jan 30 2025 19:45:55
Module start 'layout'
Timing: Jan 30 2025 19:45:55
Module start 'content'
Timing: Jan 30 2025 19:45:55
Module end 'content'
Timing: Jan 30 2025 19:45:55
Script end

Main resources:

Total runtime0.0217 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 588.1250151.2109
Module start 'layout' 0.00570.0038 739.3359220.6875
Module start 'content' 0.00940.0108 960.02341,009.7891
Module end 'content' 0.02030.0014 1,969.812541.9922
Script end 0.0217  2,011.8047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002511.3318140.0002
Check MTime0.00104.6788140.0001
Mysql Total
Database connection0.00073.030610.0007
Mysqli_queries0.003616.378430.0012
Looping result0.00000.059310.0000
Template Total0.00104.410.0010
Template load0.00073.352310.0007
Template processing0.00021.072810.0002
Override
Cache load0.00052.367410.0005
General
dbfile0.00031.211180.0000
String conversion0.00000.034040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs