【问题标题】:How can I judge a variable whether is assign in Smarty template?如何判断变量是否在 Smarty 模板中赋值?
【发布时间】:2018-12-28 09:44:53
【问题描述】:

我有一个聪明的项目。在 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 smarty


【解决方案1】:

你可以使用PHP的isset函数。

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

【讨论】:

  • 但是这是在 smarty 模板中,这是使用 PHP 的 isset 吗?还是 smarty 模板语法的 isset?
  • 试试看你就知道了。它使用 PHP 的 isset。
猜你喜欢
  • 2011-05-29
  • 2015-07-05
  • 1970-01-01
  • 2010-09-05
  • 1970-01-01
  • 2016-06-18
  • 1970-01-01
  • 2011-12-11
  • 1970-01-01
相关资源
最近更新 更多