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.

eZ debug

Timing: Jan 19 2025 03:22:23
Script start
Timing: Jan 19 2025 03:22:23
Module start 'layout'
Timing: Jan 19 2025 03:22:23
Module start 'content'
Timing: Jan 19 2025 03:22:24
Module end 'content'
Timing: Jan 19 2025 03:22:24
Script end

Main resources:

Total runtime1.5519 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 589.4141152.6563
Module start 'layout' 0.00520.0032 742.070339.5078
Module start 'content' 0.00841.5421 781.5781481.7266
Module end 'content' 1.55050.0014 1,263.304712.0938
Script end 1.5519  1,275.3984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.2170160.0002
Check MTime0.00140.0873160.0001
Mysql Total
Database connection0.00080.052910.0008
Mysqli_queries1.500096.6580570.0263
Looping result0.00060.0391550.0000
Template Total1.512597.520.7562
Template load0.00210.138320.0011
Template processing1.510397.320020.7552
Template load and register function0.00020.014810.0002
states
state_id_array0.00160.106210.0016
state_identifier_array0.00380.247020.0019
Override
Cache load0.00180.1176370.0000
Sytem overhead
Fetch class attribute can translate value0.00070.046820.0004
Fetch class attribute name0.00110.068930.0004
XML
Image XML parsing0.00020.013920.0001
class_abstraction
Instantiating content class attribute0.00000.000430.0000
General
dbfile0.00140.0874100.0001
String conversion0.00000.000440.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/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs