ppbitb
ppbitb

Reputation: 517

Smarty: Is there a way to detect whether all expected variables were passed to the template?

Let's say I have a smarty template file with the following content:

<div>
        var 1: {$var1}<br>
        var 2: {$var2}
</div>

and I do the following assignment where I forget to assign var2:

$smarty->assign("var1", "foo");
$smarty->display($tpl_file);

What is the best way to detect that not all the required variables were assigned?

Thank you.

Upvotes: 1

Views: 232

Answers (1)

hakre
hakre

Reputation: 198116

Smarty itself does not have such a function, you can try to write something your own like:

preg_match_all('/{\$(.*?)}/', file_get_contents('templates/index.tpl'), $vars, 2);

foreach ($vars as $v)
{
    echo $v[1]."<br>";
}

Taken from here: http://smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions#project-10

Upvotes: 1

Related Questions