Templ. lang.: How to check content object attribute values?

Author Message

Don Ronaldo

Monday 16 February 2009 6:41:17 am

Hi eZ forum!

How do I check in a template, if an attribute of a content object has any value or has been left empty?

I have already tried several options, however, none of it worked. I want to achive something like:

{if not(empty($node.object.data_map.attribute_name, ''))}
<div>{attribute_view_gui attribute=$node.object.data_map.attribute_name}</div>
{else}
<div>Attribute not set.</div>
{/if}

Thanks in advance for any hint.
Ron.

Helle Andersen

Monday 16 February 2009 7:34:22 am

Hi Ron
It depends on the datatype of the attribute:

XML attribut:e

{if $node.object.data_map.arbejdsomraade.content.is_empty|not}
<h1>Arbejdsomraade:</h1>
{attribute_view_gui attribute=$node.object.data_map.arbejdsomraade}
{/if}

Text line, images, emails and URL attribut:e

{if $node.object.data_map.fornavn.content}
        <strong>{attribute_view_gui attribute=$node.object.data_map.fornavn}</strong>
{/if}

Image example:

{if $node.object.data_map.billede.content}
<img align="right ..>
{/if}

Matrix:

{if $node.object.data_map.xx.content.rows.sequential}
{attribute_view_gui attribute=$node.object.data_map.xx}
{/if}

ISBN:

{if $object.data_map.isbn.content|not}
{/if}

Time-date field

{if $node.object.data_map.sluttidspunkt.content.is_valid}
{/if}

Object relation (only one option)

{if $node.object.data_map.xxxx.content}
{attribute_view_gui attribute=$node.object.data_map.xxxx}
{/if}

Object relation list

{if $node.object.data_map.xxx.content.relation_list|count|gt( 0 )}
{attribute_view_gui attribute=$node.object.data_map.xxx}
{/if}

Don Ronaldo

Monday 16 February 2009 8:48:24 am

Hi Helle,

thanks a lot. Exactly, what I was looking for!

cheers,
Ron.

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