Nest Loops

Author Message

Starla Carpenter

Thursday 11 March 2004 6:27:57 pm

Nested loops are driving me mad!
(Actually the whole template thing is driving me mad. Anyone have any suggestions of where I can go to get educated?)

I have working code that displays events (shop items)that have been paid for and allows the user to register for them. (I realize that the option part probably doesn't have to be a loop, and I'd appreciate help eliminating that as well.) My real issue, however, is that I want to have an inner loop based on the the count associated with the event. So if someone purchased 3 registrations to an event, they would get three lines allowing them to put a different name for each registration. I had a lame attempt at a loop, but it didn't print out anything but the name input field (the correct number of times, however).

Thanks in advance for any help.

-Starla

<TABLE>
{section name=ProductItem loop=$order.product_items show=$order.product_items sequence=array(bglight,bgdark)}

<tr>
<td >{$ProductItem:item.object_name}<input type='hidden' name="eventName[]" value = "{$ProductItem:item.object_name}"> </TD>

{section name=Options loop=$ProductItem:item.item_object.option_list}
<td>{$ProductItem:Options:item.value}<input type='hidden' name="eventoption[]" value ="{$ProductItem:Options:item.value}"></TD>
{/section}

<TD>Name: </TD><TD><input type='text' name="regName[]"></TD>

</TR>

{/section}
</TABLE>

Tobias Persson

Thursday 11 March 2004 11:38:02 pm

I had about the same problems at first. I solved it by not using the name attribute in sections. Try something like this:

<TABLE>
{section loop=$order.product_items show=$order.product_items sequence=array(bglight,bgdark)}

<tr>
<td >{$:item.object_name}<input type='hidden' name="eventName[]" value = "{$:item.object_name}"> </TD>

{section loop=$:item.item_object.option_list}
<td>{$:item.value}<input type='hidden' name="eventoption[]" value ="{$:item.value}"></TD>
{/section}

<TD>Name: </TD><TD><input type='text' name="regName[]"></TD>

</TR>

{/section}
</TABLE>

Paul Forsyth

Friday 12 March 2004 2:03:04 am

If you are using 3.3 you can use the new section 'var' parameter. This greatly simplifies the need for names everywhere.

Eg:

{section loop=$loop var=Myloop}
{$MyLoop.item}

{section loop=$loop2 var=MyOtherloop}
{$MyOtherLoop.item}
{/section}

{/section}

Take a look at the new doco:

http://ez.no/ez_publish/documentation/reference/template_functions/program_flow/section

paul

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 19 2025 00:17:58
Script start
Timing: Jan 19 2025 00:17:58
Module start 'layout'
Timing: Jan 19 2025 00:17:58
Module start 'content'
Timing: Jan 19 2025 00:17:58
Module end 'content'
Timing: Jan 19 2025 00:17:58
Script end

Main resources:

Total runtime0.6305 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0051 589.2188152.6094
Module start 'layout' 0.00510.0025 741.828139.3984
Module start 'content' 0.00760.6209 781.2266549.0703
Module end 'content' 0.62840.0021 1,330.296912.2031
Script end 0.6305  1,342.5000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.5296160.0002
Check MTime0.00150.2341160.0001
Mysql Total
Database connection0.00060.098510.0006
Mysqli_queries0.570690.4881590.0097
Looping result0.00060.0920570.0000
Template Total0.601695.420.3008
Template load0.00200.312120.0010
Template processing0.599695.087620.2998
Template load and register function0.00020.026710.0002
states
state_id_array0.00120.194410.0012
state_identifier_array0.00080.125220.0004
Override
Cache load0.00160.2469430.0000
Sytem overhead
Fetch class attribute can translate value0.00060.098530.0002
Fetch class attribute name0.00180.290240.0005
XML
Image XML parsing0.00370.593630.0012
class_abstraction
Instantiating content class attribute0.00000.001740.0000
General
dbfile0.00490.7714160.0003
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs