Forums / Setup & design / Correct use of the "or" operator?
Fraser Hore
Sunday 16 October 2005 2:33:21 pm
I'm using a fetch of the attributes of a class to be able to use the attribute names as column headers of a table. The trick bit is i'd like to be able to set the attributes that are printed and therefore the columns that are created. With an if eq statement I can get a match on one attribute identifier (see below), but i'd like to be able to test against the array of desired attributes/columns. I tried to use the or operator (see commented out line) but i'm not sure exactly how it works. Any suggestions?
{*gather attributes for a node object’s class and assign to $attributes variable*}{def $attributes=fetch( 'content', 'class_attribute_list', hash( 'class_id', $class.object.contentclass_id ) )}
{*start the table*}<table border="1">
{*create the headers row using each attribute name as a column header*} <th> <tr> {foreach $attributes as $attribute} {if eq( $attribute.identifier, 'organization_name')} {*if or( $attribute.identifier [, organization_name' [, 'org_type']])*} <td> {$attribute.name|wash} </td> {/if} {/foreach} </tr></th>
Thanks!
Fraser
Bruce Morrison
Sunday 16 October 2005 5:26:14 pm
Hi Fraser
I think you are after something like:
{*gather attributes for a node object's class and assign to $attributes variable*} {def $attributes=fetch( 'content', 'class_attribute_list', hash( 'class_id', $class.object.contentclass_id ) )} {*start the table*} <table border="1"> {*create the headers row using each attribute name as a column header*} <th> <tr> {foreach $attributes as $attribute} {if or(eq( $attribute.identifier, 'organization_name'),eq( $attribute.identifier ,'org_type'))} <td> {$attribute.name|wash} </td> {/if} {/foreach} </tr> </th>
CheersBruce
My Blog: http://www.stuffandcontent.com/ Follow me on twitter: http://twitter.com/brucemorrison Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish
Monday 17 October 2005 10:30:02 am
Brilliant! Thanks Bruce it worked!
The examples in the documentation for the "or" operator really threw me off. I couldn't figure out what was being compared and assumed it was the first parameter. Your code makes a lot more sense.
Cheers,