Forums / Install & configuration / Nested loops

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.

eZ debug

Timing: Jan 18 2025 03:11:13
Script start
Timing: Jan 18 2025 03:11:13
Module start 'content'
Timing: Jan 18 2025 03:11:14
Module end 'content'
Timing: Jan 18 2025 03:11:14
Script end

Main resources:

Total runtime0.7293 sec
Peak memory usage4,096.0000 KB
Database Queries219

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0099 591.3203180.8438
Module start 'content' 0.00990.6084 772.1641808.2344
Module end 'content' 0.61830.1109 1,580.3984344.4453
Script end 0.7292  1,924.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.5837210.0002
Check MTime0.00160.2173210.0001
Mysql Total
Database connection0.00110.148210.0011
Mysqli_queries0.629286.26962190.0029
Looping result0.00200.26932170.0000
Template Total0.695695.420.3478
Template load0.00240.329020.0012
Template processing0.693195.042720.3466
Template load and register function0.00020.025910.0002
states
state_id_array0.00140.194810.0014
state_identifier_array0.00100.133320.0005
Override
Cache load0.00230.31041230.0000
Sytem overhead
Fetch class attribute can translate value0.00190.257080.0002
Fetch class attribute name0.00080.1114110.0001
XML
Image XML parsing0.00260.352880.0003
class_abstraction
Instantiating content class attribute0.00000.0023110.0000
General
dbfile0.00300.4168400.0001
String conversion0.00000.001230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
17content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
12content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 42
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs