Glo*_*ish 8 php template-engine smarty
如何检查特定值是否已分配给Smarty,如果没有分配(默认)值?
回答:
if ($this->cismarty->get_template_vars('test') === null) {
$this->cismarty->assign('test', 'Default value');
}
Run Code Online (Sandbox Code Playgroud)
And*_*ndy 15
Smarty 2
if ($smarty->get_template_vars('foo') === null)
{
$smarty->assign('foo', 'some value');
}
Run Code Online (Sandbox Code Playgroud)
Smarty 3
if ($smarty->getTemplateVars('foo') === null)
{
$smarty->assign('foo', 'some value');
}
Run Code Online (Sandbox Code Playgroud)
请注意,对于Smarty 3,您将不得不使用$smarty->getTemplateVars.