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?