Change sentinel value inside a switch - possible scope issue

Author Message

James Ward

Tuesday 30 September 2003 2:20:59 pm

Hi all.
I would like to create a section that does something different on the first iteration than for all subsequent iterations.

I am attempting to fetch related objects for my example. I placed the following code in an article with 3 related objects:

{let runcheck=0}
{section show=count($node.object.related_contentobject_array)|gt(0)}
{section name=Rel loop=$node.object.related_contentobject_array}
{switch name=FirstRun match=$runcheck}
{case match=0}
First Run runcheck = {$runcheck}<br />
{set $runcheck=1}
{/case}
{case}
Sebsequent Run runcheck = {$runcheck}<br />
{/case}
{/switch}
{/section}
{/section}
{/let}

This returns:
First Run runcheck = 0
First Run runcheck = 0
First Run runcheck = 0

Hardly the desired result. I tried using $#runcheck=1 but it made no difference. I read the documentation on let and set and namespaces. Is it even possible for me to change the value of $runcheck inside my switch or do I need to come at this another way?

Thanks in advance.

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Friday 03 October 2003 10:14:57 am

O.K. I'm a little closer to a solution.
Instead of using a sentinel value inside the switch I check the index of the section to see which itteration I'm on. The problem now is how to close my table. Currently the </table> appears regardless of the <table> tag. This can create some dandy layout problems.
Is there a way to check if I am on the last itteration of a section, or a way to set a sentinel variable inside a section so I can tell if its code was run?

Here is the code I am currently using. If someone else has a better way of listing related objects I'd love to hear it.

{*Related Objects List*}
{section name=total show=count($node.object.related_contentobject_array)|gt(0)}
{section name=Rel loop=$node.object.related_contentobject_array}
{section-exclude match=$:item.contentclass_id|eq(5)}
{switch match=$:index}
{case match=0}
<table width="150" border=0 cellpadding=3 cellspacing=0 class="related-information-table">
<tr>
<td class="related-information-title">Related Information</td>
</tr>
<tr>
<td><ul>
<li><a class="related-information-link" href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}
{case}
<li><a class="related-information-link" href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}
{/switch}
{/section}
</ul></td>
</tr>
</table>
{/section}
{*End Related Objects List*}

working at www.wardnet.com
blogging at www.jamesward.ca

James Ward

Wednesday 08 October 2003 12:55:38 pm

Here is the working code to create a related object table, allowing you to relate articles without adding any objects to the article itself. Just add the related item and the code will take care of the rest. Use the section exclude to eliminate classes which are related for inclusion in the reference article.

Thanks to Vidar Langseid for the corrected code.

{*Related Objects List*}
{let enableendtag=0 name=Rel}
{section show=count($node.object.related_contentobject_array)|gt(0)}
{section loop=$node.object.related_contentobject_array}
{section-exclude match=$:item.contentclass_id|eq(5)}
{switch match=$:index}
{case match=0}
{* if starttag *}
{set enableendtag=1}
<table width="150" border=0 cellpadding=3 cellspacing=0 class="related-information-table">
<tr>
<td align="center"><img src={"related.gif"|ezimage} width="143" height="16" alt="anemia awareness week" border="0" /></td>
</tr>
<tr>
<td><ul>
<li><a class="related-information-link" href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}
{case}
<li><a class="related-information-link" href={concat("/content/view/full/",$:item.main_node.node_id)|ezurl}>{$:item.name}</a></li>
{/case}
{/switch}
{/section}
{section show=$:enableendtag}
</ul></td>
</tr>
</table>
{/section}
{/section}
{/let}

working at www.wardnet.com
blogging at www.jamesward.ca

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 31 2025 03:26:22
Script start
Timing: Jan 31 2025 03:26:22
Module start 'layout'
Timing: Jan 31 2025 03:26:22
Module start 'content'
Timing: Jan 31 2025 03:26:23
Module end 'content'
Timing: Jan 31 2025 03:26:23
Script end

Main resources:

Total runtime1.2708 sec
Peak memory usage8,192.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.5234151.2422
Module start 'layout' 0.00600.0039 740.7656220.7500
Module start 'content' 0.00991.2601 961.51564,426.3984
Module end 'content' 1.26990.0008 5,387.914115.7813
Script end 1.2707  5,403.6953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2680160.0002
Check MTime0.00120.0938160.0001
Mysql Total
Database connection0.00060.047710.0006
Mysqli_queries1.163991.5903550.0212
Looping result0.00050.0381530.0000
Template Total1.173092.320.5865
Template load0.00220.175320.0011
Template processing1.170892.129920.5854
Template load and register function0.00130.105210.0013
states
state_id_array0.00400.312510.0040
state_identifier_array0.00190.149520.0009
Override
Cache load0.00200.1580910.0000
Sytem overhead
Fetch class attribute can translate value0.00190.147410.0019
Fetch class attribute name0.00190.146840.0005
XML
Image XML parsing0.00170.133310.0017
class_abstraction
Instantiating content class attribute0.00000.002960.0000
General
dbfile0.01010.7951160.0006
String conversion0.00000.000640.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs