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.

eZ debug

Timing: Jan 18 2025 11:02:11
Script start
Timing: Jan 18 2025 11:02:11
Module start 'layout'
Timing: Jan 18 2025 11:02:11
Module start 'content'
Timing: Jan 18 2025 11:02:11
Module end 'content'
Timing: Jan 18 2025 11:02:11
Script end

Main resources:

Total runtime0.0140 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.3516152.6250
Module start 'layout' 0.00560.0024 741.976639.4453
Module start 'content' 0.00800.0042 781.421993.4609
Module end 'content' 0.01220.0018 874.882834.3047
Script end 0.0140  909.1875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002517.6854140.0002
Check MTime0.00117.5863140.0001
Mysql Total
Database connection0.00149.620310.0014
Mysqli_queries0.001913.323530.0006
Looping result0.00000.079810.0000
Template Total0.001510.510.0015
Template load0.00075.219410.0007
Template processing0.00075.205810.0007
Override
Cache load0.00053.781210.0005
General
dbfile0.00031.927180.0000
String conversion0.00000.069640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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