Forums / Setup & design / Nest Loops

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