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

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 18 2025 19:01:07
Script start
Timing: Jan 18 2025 19:01:07
Module start 'layout'
Timing: Jan 18 2025 19:01:07
Module start 'content'
Timing: Jan 18 2025 19:01:08
Module end 'content'
Timing: Jan 18 2025 19:01:08
Script end

Main resources:

Total runtime1.4922 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.0151 588.3906152.6875
Module start 'layout' 0.01510.0035 741.078139.5078
Module start 'content' 0.01861.4719 780.5859472.8906
Module end 'content' 1.49050.0016 1,253.476612.0938
Script end 1.4921  1,265.5703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00550.3683160.0003
Check MTime0.00160.1066160.0001
Mysql Total
Database connection0.00390.259610.0039
Mysqli_queries1.385992.8780570.0243
Looping result0.00060.0429550.0000
Template Total1.406994.320.7034
Template load0.00230.152320.0011
Template processing1.404694.129220.7023
Template load and register function0.00030.018910.0003
states
state_id_array0.00490.326010.0049
state_identifier_array0.00440.293120.0022
Override
Cache load0.00200.1320320.0001
Sytem overhead
Fetch class attribute can translate value0.00080.055620.0004
Fetch class attribute name0.01270.850730.0042
XML
Image XML parsing0.00040.024320.0002
class_abstraction
Instantiating content class attribute0.00000.001430.0000
General
dbfile0.00980.6547100.0010
String conversion0.00000.000840.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
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs