How do I check to see if a Smarty variable is already assigned?

GloryFish picture GloryFish · Dec 8, 2008 · Viewed 14.6k times · Source

How do I check to see if a particular value has already been assigned to Smarty and if not assign a (default) value?

Answer:

if ($this->cismarty->get_template_vars('test') === null) {
   $this->cismarty->assign('test', 'Default value');
}

Answer

Andy picture Andy · Dec 8, 2008

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');
}

Note that for Smarty 3, you will have to use $smarty->getTemplateVars instead.