Rating: 3.5/5
(2 votes cast)
Login to Rate
Sometimes you just need to see what variables are available in an array in Smarty. In PHP this is usually done using print_r($foo) where $foo is your array. But in smarty this is done using the following method.
{$foo|@print_r}
When you use this command I recommend placing open and closing pre tags around the command to ensure the output is formatted in a readable format.
The @ tells smarty to pass the entire array to the modifier rather than calling the modifier for each element of the array. Smarty also ships with a modifier that does similar to print_r(): {$foo|@debug_print_var}. You may also consider Smartys debug facility (which you can enable in-template by inserting a {debug} tag or you can enable by configuring the Smarty object appropriately - see the docs for more info)
{$foo|@print_r}
Replace $foo with a smarty array.

Thanks for sharing :)