Debugging in Smarty template

Print Friendly

While trying to debug a variable in PHP i love the var_dump() method. Off course i have debugger tools like xDebug enabled in my IDE i love using var_dumps. One of the thing i like about var_dump is it gives the complete structure of an object at that instance. Using MVC model for PHP usually ties you up with a framework and a choice of view. For Zend it is smarty which i use, and smarty is not straight forward to debug like PHP. After some research i found out various ways to use var_dump. Here are they:

Method 1:

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

Using php tags is not good practice and ideally they should be disabled for security reasons anyway

Method 2:


It only outputs the values and not the keynames, and there are no spaces between the values, so it’s not ideal for debugging.

Method 3:


Method 4:


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

Method 5:


Few of these methods are taken from StackOverflow. If you know more do comment or cite them. Will update the list.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)


  1. […] Debugging in Smarty template […]