如何检查是否已经分配了 Smarty 变量? [英] How do I check to see if a Smarty variable is already assigned?
本文介绍了如何检查是否已经分配了 Smarty 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查是否已将特定值分配给 Smarty,如果未分配(默认)值?
How do I check to see if a particular value has already been assigned to Smarty and if not assign a (default) value?
答案:
if ($this->cismarty->get_template_vars('test') === null) {
$this->cismarty->assign('test', 'Default value');
}
推荐答案
Smarty 2
if ($smarty->get_template_vars('foo') === null)
{
$smarty->assign('foo', 'some value');
}
Smarty 3
if ($smarty->getTemplateVars('foo') === null)
{
$smarty->assign('foo', 'some value');
}
请注意,对于 Smarty 3,您必须改用 $smarty->getTemplateVars
.
Note that for Smarty 3, you will have to use $smarty->getTemplateVars
instead.
这篇关于如何检查是否已经分配了 Smarty 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文