Forums / Developer / Change sentinel value inside a switch - possible scope issue

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

eZ debug

Timing: Jan 18 2025 15:09:52
Script start
Timing: Jan 18 2025 15:09:52
Module start 'content'
Timing: Jan 18 2025 15:09:53
Module end 'content'
Timing: Jan 18 2025 15:09:53
Script end

Main resources:

Total runtime1.0262 sec
Peak memory usage4,096.0000 KB
Database Queries192

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0062 589.8672180.7969
Module start 'content' 0.00620.9130 770.6641524.0469
Module end 'content' 0.91930.1069 1,294.7109336.7109
Script end 1.0262  1,631.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.3638210.0002
Check MTime0.00140.1395210.0001
Mysql Total
Database connection0.00070.064410.0007
Mysqli_queries0.951592.72171920.0050
Looping result0.00150.15091900.0000
Template Total1.001397.620.5007
Template load0.00170.169620.0009
Template processing0.999697.400820.4998
Template load and register function0.00010.007410.0001
states
state_id_array0.00060.062810.0006
state_identifier_array0.00090.088120.0005
Override
Cache load0.00160.1546910.0000
Sytem overhead
Fetch class attribute can translate value0.00090.091420.0005
Fetch class attribute name0.00090.089240.0002
XML
Image XML parsing0.00060.058220.0003
class_abstraction
Instantiating content class attribute0.00000.001460.0000
General
dbfile0.00240.2327270.0001
String conversion0.00000.000530.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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