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.