开发者

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}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜