how to know if a variable is set?

Author Message

marc marc

Thursday 16 October 2008 8:21:28 am

Hello everybody,

i would like to show a textfield and its title in an article only if this field is set, that means if theres is no text in the textfield, the title won't appear. i know in PHP there is the 'isset' condition that return true if the variable is not empty, but i didnt find anything in ezpublish that is similar.

thank you for your help.

justin kazadi

Thursday 16 October 2008 8:40:51 am

Hi,
if you want to know if an attribute named title for exemple is set you can use this:

{if $node.data_map.title.has_content}
{do same thing}
{/if}

The theory is when we know everything and nothing works.
The practice is when everything works and nobody knows why.
If the practice and theory are met, nothing works and we do not know why.

Albert Einstein

Piotrek Karaƛ

Thursday 16 October 2008 10:31:35 am

Justin,
If you explicitly refer in a conditional statement to an inexistent variable, a warning or a notice will be thrown. This is exactly why isset-like functions exist, and eZ has those as well:
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/variable_and_type_handling/is_set
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/variable_and_type_handling
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/data_and_information_extraction/ezhttp_hasvariable
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/data_and_information_extraction/ezini_hasvariable
...
Hope this helps,
Cheers,
Piotrek

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

marc marc

Friday 17 October 2008 1:27:40 am

thank you for your help, i try right now

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.