Debug Smarty

good morning phpstorm,

is there a way in phpstorm where i can set a breakpoint in a smarty template (*.tpl) file and debug smarty templates?  i want to be able to debug smarty variables and inspect their values like how i would set breakpoints in php and js files and inspect the values of their variables.

thank you very much for your help on this matter.

sam

5 comments
Comment actions Permalink

Hi Sam,

Yes -- you can set breakpoint in already compiled Smarty template.

Obviously
1) "force recompile" (or how that Smarty option is properly called) has to be set to false -- which is by default.
2) the folder with compiled templates must be part of the project (usually you would like to have it to be excluded (together with the rest of temp folders) so that PhpStorm does not index them)

The algorithm is as follow:
1) run the script normally, so that Smarty will compile your template
2) do not make any changes to this template & ensure that compiled template remains the same (in case you have "cached" sections)
3) set your breakpoints
4) run script in debug mode

Alternatively you can debug all way through Smarty class files, catch the moment when template got compiled and saved to file .. and set breakpoints in that newly created file (much longer and inconvenient).


On another hand -- why do you need to debug template itself (unless you have & want to debug {php} sections in Smarty template (which, in my opinion, defeats the point of using Smarty))?. The proper way is to debug the code that collects/generates data and passes it to Smarty & use "debug = true" option of Smarty if required (to see what data was actually passed).

P.S.
Please note, I have tried this myself over an year ago in another IDE. But it should work in PhpStorm as well -- see no reasons why not.


RE: debugging JS that is included in such templates -- I personally use Firebug in such situation.

P.P.S.
The whole text above is regarding PHP debug, not JavaScript (I have not used Php/WebStorm for JavaScript debugging yet).

0
Comment actions Permalink

Good morning Andriy,

Thank you soooooooooooo very much for your insight and expertise on this matter...  I really appreciate it a lot...  and you are correct, Javascript should be debugged in firebug which I always do...  I don't plan to use the {php} syntax in the Smarty Templates due to what I read on the Smarty website, and what you mentioned about the {php} is inline with what was mentioned on the Smarty site.

So based on what was mentionioned in your response, the best and simplest way for me to set breakpoints and debug Smarty Templates is to do it in the compiled templates?  Would that be correct?

Thank you Andriy

Sam

0
Comment actions Permalink

Hi Sam,

So based on what was mentionioned in your response, the best and simplest way for me to set breakpoints and debug Smarty Templates is to do it in the compiled templates?  Would that be correct?

If you need to actually debug the Smarty template -- then yes.


But I would recommend to debug the code that collects/generates data and passes it to Smarty instead -- the actual code that does the job (and use "debug = true" option of Smarty if required -- to see what data was actually received by Smarty).

0
Comment actions Permalink

Im not sure if its a feature of smarty itself of the CMS that i use, but if i want to know what variable values are in a smarty template then i put {debug} into the template.tpl file where i want to know and when the page is viewed a popup window will appear with all the variables available in that template.

Does that help?

0
Comment actions Permalink

If you're using Smarty3, you can also do the following:

{var_dump($var)}

0

Please sign in to leave a comment.