[php] How to Debug Variables in Smarty like in PHP var_dump()

I have some variables inside a template and I don't know where I assigned them. I need to know what is inside a particular variable; for instance, say I have a variable in smarty called member. I tried with {debug} but it didn't work, and no popup was shown.

How can I output/debug smarty variables using something like var_dump() inside the templates?

This question is related to php templates debugging smarty

The answer is


In new Smarty it is:

<pre>
{var_dump($variable)}
</pre>

I prefer to use <script>console.log({$varname|@json_encode})</script> to log to the console.


Try out with the Smarty Session:

{$smarty.session|@debug_print_var}

or

{$smarty.session|@print_r}

To beautify your output, use it between <pre> </pre> tags


If you want something prettier I would advise

{"<?php\n\$data =\n"|@cat:{$yourvariable|@var_export:true|@cat:";\n?>"}|@highlight_string:true}

just replace yourvariable by your variable


try this .... Set $debugging to TRUE in Smarty.


In smarty there is built in modifier you could use that by using | (single pipeline operator). Like this {$varname|@print_r} will print value as print_r($php_variable)


{$variable|@debug_print_var nofilter} and you not need to add "<pre>" tags

{$variable|var_dump} show you more (but worse formatting) because debug_print_var not showing private variable in object!


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


To debug in smarty in prestashop 1.6.x :

{ddd($variable)} -> debug and die

{ppp($variable)} -> debug only

An onther usefull debug tag :

{debug}

in smarty V3 you can use this

{var_dump($variable)}


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.


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


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to templates

*ngIf else if in template 'if' statement in jinja2 template How to create a link to another PHP page Flask raises TemplateNotFound error even though template file exists Application not picking up .css file (flask/python) Django: How can I call a view function from template? Angularjs Template Default Value if Binding Null / Undefined (With Filter) HTML email in outlook table width issue - content is wider than the specified table width How to redirect on another page and pass parameter in url from table? How to check for the type of a template parameter?

Examples related to debugging

How do I enable logging for Spring Security? How to run or debug php on Visual Studio Code (VSCode) How do you debug React Native? How do I debug "Error: spawn ENOENT" on node.js? How can I inspect the file system of a failed `docker build`? Swift: print() vs println() vs NSLog() JavaScript console.log causes error: "Synchronous XMLHttpRequest on the main thread is deprecated..." How to debug Spring Boot application with Eclipse? Unfortunately MyApp has stopped. How can I solve this? 500 internal server error, how to debug

Examples related to smarty

How to Debug Variables in Smarty like in PHP var_dump() What are .tpl files? PHP, web design