Forums / Developer / Testing existence of a post/get variable in templates

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?

eZ debug

Timing: Jan 18 2025 01:13:03
Script start
Timing: Jan 18 2025 01:13:03
Module start 'content'
Timing: Jan 18 2025 01:13:03
Module end 'content'
Timing: Jan 18 2025 01:13:03
Script end

Main resources:

Total runtime0.1904 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0080 588.9922180.8125
Module start 'content' 0.00800.0074 769.804798.0547
Module end 'content' 0.01540.1750 867.8594526.6250
Script end 0.1904  1,394.4844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00402.0958200.0002
Check MTime0.00160.8180200.0001
Mysql Total
Database connection0.00080.420610.0008
Mysqli_queries0.132869.72111410.0009
Looping result0.00170.87211390.0000
Template Total0.174791.710.1747
Template load0.00110.554510.0011
Template processing0.173691.165210.1736
Override
Cache load0.00080.419010.0008
Sytem overhead
Fetch class attribute can translate value0.00100.526210.0010
XML
Image XML parsing0.00030.147610.0003
General
dbfile0.00703.6726200.0003
String conversion0.00000.004330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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