Forums / Setup & design / Templ. lang.: How to check content object attribute values?

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.

eZ debug

Timing: Jan 19 2025 01:00:02
Script start
Timing: Jan 19 2025 01:00:03
Module start 'content'
Timing: Jan 19 2025 01:00:03
Module end 'content'
Timing: Jan 19 2025 01:00:03
Script end

Main resources:

Total runtime0.5516 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0747 589.2109180.7969
Module start 'content' 0.07470.0612 770.007893.9922
Module end 'content' 0.13590.4156 864.0000522.9219
Script end 0.5515  1,386.9219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.02564.6327200.0013
Check MTime0.02304.1617200.0011
Mysql Total
Database connection0.00951.718910.0095
Mysqli_queries0.251545.59871410.0018
Looping result0.00280.50931390.0000
Template Total0.405173.410.4051
Template load0.02254.077210.0225
Template processing0.382669.367010.3826
Override
Cache load0.02224.015410.0222
Sytem overhead
Fetch class attribute can translate value0.00120.218310.0012
XML
Image XML parsing0.00030.058210.0003
General
dbfile0.078514.2244200.0039
String conversion0.00000.001730.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs