开发者

How can I check if a variable exists in Smarty?

开发者 https://www.devze.com 2023-04-12 13:07 出处:网络
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:

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

精彩评论

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