How to test for existance of variable

Author Message

/dev/null

Friday 29 December 2006 12:40:02 am

<b>Question</b>

How would one test for existence of a template variable, or template object item ($module_result.node_id) without triggering template error, warning or notice when the 'node_id' does not exist?

I am tuning all my custom templates for performance. I am finding errors of this nature are accumulating in my custom templates. I have not yet seen how to avoid this problem.

<b>Example - Error</b>

Error: eZTemplate @ extension/example_com/design/example_com/templates/page_head.tpl:30[7]  	Dec 29 2006 03:10:56

No such attribute for array(7): node_id
Choose one of following: content, is_default_navigation_part, navigation_part,
                         ui_context, ui_component, path, uri

<b>Example - Template</b>
file, 'extension/example_com/design/example_com/templates/page_head.tpl'

<title>{if $module_result.node_id|eq(2)}{$site.title|wash}: {$site.description|wash} : Home{else}{$site_title}{/if}</title>

<b>Example - Url/Uri</b>
http://example.com/shop/checkout

<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

Kristof Coomans

Friday 29 December 2006 1:12:36 am

Hi /dev/null

You can use the is_set operator: http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/variable_and_type_handling/is_set

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

/dev/null

Friday 29 December 2006 1:19:18 am

That Worked Great!

Many Thanks!
<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

Kristof Coomans

Friday 29 December 2006 2:51:07 am

I added a page to eZpedia which makes it easier for people familiar with PHP to switch to the template language: http://ezpedia.org/wiki/en/ez/template_language_for_php_developers

I'm not sure this helps you /dev/null. If you are familiar with other template/scripting/programming languages, feel free to add your own page on eZpedia to compare them with the eZ template language.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

/dev/null

Friday 29 December 2006 3:30:45 am

Kristof!

That is a very fine page! <i>I know I have pine'd for such a page of documentation on several occasions in the past. Thank you</i>

Perhaps entries could be added for asp.net, cfml, perl, sql, ruby, python by others if needed, which would be the first language after php to add an entry for??

<i>/dev/null</i>

eZpedia community documentation project: http://ezpedia.org

Kristof Coomans

Friday 29 December 2006 3:38:20 am

sql seems rather strange to compare with the template language ;-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

David Boman

Friday 29 December 2006 7:28:08 am

I agree with /dev/null - this is a very good page and I know for sure that I will use it alot when i code templates! Thanks!

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:33:56
Script start
Timing: Jan 18 2025 11:33:56
Module start 'layout'
Timing: Jan 18 2025 11:33:56
Module start 'content'
Timing: Jan 18 2025 11:33:57
Module end 'content'
Timing: Jan 18 2025 11:33:57
Script end

Main resources:

Total runtime0.8266 sec
Peak memory usage4,096.0000 KB
Database Queries71

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0095 587.9297152.6250
Module start 'layout' 0.00950.0037 740.554739.4453
Module start 'content' 0.01320.8116 780.0000624.5938
Module end 'content' 0.82480.0017 1,404.593816.1563
Script end 0.8266  1,420.7500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.4476160.0002
Check MTime0.00130.1626160.0001
Mysql Total
Database connection0.00140.174810.0014
Mysqli_queries0.753591.1599710.0106
Looping result0.00070.0901690.0000
Template Total0.786495.120.3932
Template load0.00200.239920.0010
Template processing0.784494.897520.3922
Template load and register function0.00010.011610.0001
states
state_id_array0.00120.139410.0012
state_identifier_array0.00130.158220.0007
Override
Cache load0.00190.2314400.0000
Sytem overhead
Fetch class attribute can translate value0.00070.084830.0002
Fetch class attribute name0.00120.143390.0001
XML
Image XML parsing0.00130.152030.0004
class_abstraction
Instantiating content class attribute0.00000.0038130.0000
General
dbfile0.00120.1402220.0001
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
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/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: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs