Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if a variable exists in Smarty?

Tags:

php

smarty

I'm using Smarty template engine.

I'm doing a simple login page. I set a variabile named error with a message if there are some problems, but IF NOT I get:

Notice: Undefined index: error 

How could I check if this variable exists?

I only do:

{if $error}<h1>{$error}</h1>{/if} 

thanks

like image 514
Dail Avatar asked Oct 13 '11 09:10

Dail


People also ask

How do I assign a variable in smarty?

{assign var="name" value="Bob"} {assign "name" "Bob"} {* short-hand *} The value of $name is {$name}. The above example will output: The value of $name is Bob. {assign var="name" value="Bob" nocache} {assign "name" "Bob" nocache} {* short-hand *} The value of $name is {$name}.

How do you write if condition in Smarty?

{if} statements in Smarty have much the same flexibility as PHP if statements, with a few added features for the template engine. Every {if} must be paired with a matching {/if} . {else} and {elseif} are also permitted. All PHP conditionals and functions are recognized, such as ||, or, &&, and, is_array(), etc.


1 Answers

There you go!

{if isset($error)}     {* TODO something *} {/if} 
like image 174
Wesley van Opdorp Avatar answered Sep 19 '22 18:09

Wesley van Opdorp