37

How do you print all variables available in the context of a Smarty template? Something like the Django debug trace that lists everything being passed.

Thanks

4 Answers 4

74

Use {debug} From the manual:

{debug} dumps the debug console to the page. This works regardless of the debug settings in the php script. Since this gets executed at runtime, this is only able to show the assigned variables; not the templates that are in use. However, you can see all the currently available variables within the scope of a template.

$debugging = true must be enabled in your settings or class, and site popups must be unblocked to see the window

Sign up to request clarification or add additional context in comments.

6 Comments

Remember to allow popups when using {debug}. Browser blocks debug info popup by default.
still helpful in 2014 (might be for older versions of smarty though)
{debug} is available in both Smarty 2 and 3
why nobody mentions that $debugging = true must be enabled in your settings or class, and site popups must be unblocked to see the window
Sometimes, {debug} causes memory limit because of huge amount of data to display. Is there any function to call from template file to display the list of defined variables only?
|
13
var_dump($Smarty->_tpl_vars);

From the Smarty code :)

Comments

7

Updated answer for Smarty 3: getTemplateVars

// If no parameter is given, an array of all assigned variables are returned. 
$all_tpl_vars = $smarty->getTemplateVars();

Comments

0

$all_tpl_vars = $smarty->getTemplateVars(); var_dump($all_tpl_vars);

//before pushing to the template

exit;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.