Change sentinel value inside a switch - possible scope issue

Change sentinel value inside a switch - possible scope issue

Tuesday 30 September 2003 2:20:59 pm - 2 replies

Modified on Tuesday 30 September 2003 2:21:31 pm by James Ward

Author Message

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

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.