Forums / Setup & design / Attribute!=null, or how to check for actual content in an attribute.

Attribute!=null, or how to check for actual content in an attribute.

Author Message

Tore Skobba

Wednesday 07 January 2004 9:22:56 am

Hi

I have several content objects of various classes, all having an image in an attribute called "ingress". In my templates I need to do different stuff depending upon whereever there actually is an image in the ingress attribute or not. To do this I am using this code. But I have the feeling that it might not be the best solution. So does anyone else have any tips or ideas about how to do it?

{section show=is_boolean($node.object.data_map.ingress.content)}
There is an image in ingress
{section-else}
There is not an image in ingress
{/section}

I tried with is_null, but even if there weren't an image ingress.content was still different from null. I think there should be some better functionality to check for actual content in an attribute in EZ.

Cheers
Tore

Update: Found this thread (http://www.ez.no/developer/ez_publish_3/forum/setup_design/displaying_content_if_there_is_content_) dealing with the same problem. Out from that I used this:

{section show=$node.object.data_map.ingress.content)}

But I still feel like this is a very rude and ad hoc way to basically check if an attribute!=null! Are'nt there any better ways to do it?

Shurbann Martes

Wednesday 07 January 2004 10:49:10 am

Why do things difficult if it can be accomplished the easy way?

{section show=$node.object.data_map.ingress.content}

is a very good, clever and simple way to check for the content

{section show=.....}

takes any value except false. If the value is false it will skip the section. So the implementation is not "rude", but I would say clever. ;)

A programmer always use the clever and easiest way to accomplish things. And if you want the code to be readable by someone else (why you're doing the above) use comment.

-Shurbann

Tore Skobba

Wednesday 07 January 2004 4:37:43 pm

Hi

I have done it as described now, but I do not think it is a very clever way as you are directly checking on an variabel which you do not know is going to be there in future releases of EZ. What I am missing is an function for checking for actual content. Ala

{section show=is_set($node.object.data_map.ingress)}

This as a function could be rewritten if "content" where to disapper in future releases, or have different values. I belive that checking for actual content should be a mandatory function! The fact that content return "false", and not null when there is no content is not very initutive I think.

But thanks for tip:).

Cheers
Tore

eZ debug

Timing: Jan 31 2025 01:25:29
Script start
Timing: Jan 31 2025 01:25:29
Module start 'content'
Timing: Jan 31 2025 01:25:29
Module end 'content'
Timing: Jan 31 2025 01:25:29
Script end

Main resources:

Total runtime0.1858 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 588.2813370.2578
Module start 'content' 0.00660.0142 958.53911,001.5156
Module end 'content' 0.02090.1649 1,960.05473,891.6172
Script end 0.1857  5,851.6719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00412.2257200.0002
Check MTime0.00130.6903200.0001
Mysql Total
Database connection0.00080.423610.0008
Mysqli_queries0.089247.99981410.0006
Looping result0.00120.65341390.0000
Template Total0.164488.510.1644
Template load0.00070.377310.0007
Template processing0.163788.133510.1637
Override
Cache load0.00050.253110.0005
Sytem overhead
Fetch class attribute can translate value0.00201.080810.0020
XML
Image XML parsing0.00020.114210.0002
General
dbfile0.00874.6727200.0004
String conversion0.00000.003230.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