簡體   English   中英

如何判斷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}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM