Smarty模板中如何判断一个变量是否赋值?
How can I judge a variable whether is assign in Smarty template?
我有一个聪明的项目。在 php 文件中,我将动态分配变量 bar
。
在php文件对应的模板中:
{if $bar}{$bar}{/if}
但我会收到以下错误消息:
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
如何判断一个变量是否赋值?
您可以使用PHP的isset功能。
{if isset($bar)}{$bar}{/if}
我有一个聪明的项目。在 php 文件中,我将动态分配变量 bar
。
在php文件对应的模板中:
{if $bar}{$bar}{/if}
但我会收到以下错误消息:
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
如何判断一个变量是否赋值?
您可以使用PHP的isset功能。
{if isset($bar)}{$bar}{/if}