简体   繁体   English

如何判断Smarty模板中是否分配了变量?

[英]How can I judge a variable whether is assign in Smarty template?

I have a smarty project. 我有一个聪明的项目。 in the php file I will assign the variable bar dynamically. 在php文件中,我将动态分配变量bar

in the php file's corresponding template: 在php文件的相应模板中:

{if $bar}{$bar}{/if}

but I will get bellow error: 但是我会得到下面的错误:

Notice: Undefined index: bar in /Users/sof/Desktop/TestIOS/smarty-test02/templates_c/6f98597c1882f0124e0891c8343f1404eff83e24_0.file.test.tpl.cache.php on line 63

Notice: Trying to get property of non-object in /Users/sof/Desktop/TestIOS/smarty-test02/templates_c/6f98597c1882f0124e0891c8343f1404eff83e24_0.file.test.tpl.cache.php on line 63

How can I judge a variable whether is assign? 如何判断变量是否被分配?

您可以使用PHP的isset函数。

{if isset($bar)}{$bar}{/if}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM