Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Debug Variables in Smarty like in PHP var_dump()

You can use {php} tags

Method 1 (won't work in Smarty 3.1 or later):

{php}

$var =
$this->get_template_vars('var');
var_dump($var);

{/php}

Method 2:

{$var|@print_r}

Method 3:

{$var|@var_dump}

This should work:

{$var|@print_r}

or

{$var|@var_dump}

The @ is needed for arrays to make smarty run the modifier against the whole thing, otherwise it does it for each element.


For what it's worth, you can do {$varname|@debug_print_var} to get a var_dump()-esque output for your variable.


just use {debug} in your .tpl and look at your sourcecode