How can I check if a variable exists in Smarty?
I'm using Smarty template engine.
I'm doing a simple login page. I set a variabile named error wit开发者_JAVA技巧h 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
There you go!
{if isset($error)}
{* TODO something *}
{/if}
isset() - smarty - php
isset($error)
You can also use:
{if $error|default}<h1>{$error}</h1>{/if}
"|default" modifier check if variable exist and accept one param (default: empty string)
This is short :) No warnings or errors.
{if $error}
精彩评论