Reputation: 4608
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
Upvotes: 31
Views: 49154
Reputation: 649
You can also use:
{if $error|default}<h1>{$error}</h1>{/if}
"|default" modifier check if variable exist and accept one param (default: empty string)
Upvotes: 3
Reputation: 14941
There you go!
{if isset($error)}
{* TODO something *}
{/if}
Upvotes: 67