Testing existence of a post/get variable in templates

Author Message

Roberto Frascarelli

Wednesday 18 May 2005 2:08:37 am

How can I test, in templates, the existence of a
get/post variable? Using ezhttp I have the template error:

<i>Unknown post/get variable 'optvar'</i>

As example, if a form field is optional,
when not filled , it doesn't appear in POST , and when I try the template code:

...
{section show=is_set(ezhttp( 'optvar', 'post' ))}
    optvar = {ezhttp( 'optvar', 'post')}<br>
{/section}
...

It works well but it returns also the described template error.

Ɓukasz Serwatka

Monday 30 May 2005 1:15:10 am

Hi Roberto,

is_set() can check variable, ezhttp() is a function so this is a reason why is_set() returns template error.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Hans Melis

Monday 30 May 2005 1:23:24 am

Roberto,

You can't avoid that template error when using ezhttp. The code for the operator does a $http->has(Post|Get|Session)Variable() and prints the error in the else branch.

Doing an is_set on the result of ezhttp can't aleviate the problem because the error comes from the ezhttp operator itself.

It annoys me too, but it really isn't a problem with your code, nor in eZ publish's code.

Hans
http://blog.hansmelis.be

Roberto Frascarelli

Monday 30 May 2005 1:48:58 am

Ok I understand the nature of the error message,
and the bad use of the ezhttp() function in my template code, but there is only one alternative way to test the existence of a variable in post into templates...the definition of a custom template
function...right?

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 04:27:16
Script start
Timing: Jan 18 2025 04:27:16
Module start 'layout'
Timing: Jan 18 2025 04:27:16
Module start 'content'
Timing: Jan 18 2025 04:27:18
Module end 'content'
Timing: Jan 18 2025 04:27:18
Script end

Main resources:

Total runtime1.6239 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.1406152.6406
Module start 'layout' 0.00470.0031 740.781339.4766
Module start 'content' 0.00781.6148 780.2578599.2188
Module end 'content' 1.62260.0013 1,379.476612.1250
Script end 1.6239  1,391.6016 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.1911160.0002
Check MTime0.00130.0800160.0001
Mysql Total
Database connection0.00060.036710.0006
Mysqli_queries1.570996.7349620.0253
Looping result0.00070.0412600.0000
Template Total1.584197.520.7921
Template load0.00170.107520.0009
Template processing1.582397.439320.7912
Template load and register function0.00010.005710.0001
states
state_id_array0.00250.154610.0025
state_identifier_array0.00230.142020.0012
Override
Cache load0.00150.0920270.0001
Sytem overhead
Fetch class attribute can translate value0.00090.053130.0003
Fetch class attribute name0.00190.114770.0003
XML
Image XML parsing0.00160.099730.0005
class_abstraction
Instantiating content class attribute0.00000.000880.0000
General
dbfile0.00110.0682290.0000
String conversion0.00000.000640.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 20
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs