How to Debug Variables in Smarty like in PHP var_d

2020-02-16 05:58发布

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?

12条回答
叛逆
2楼-- · 2020-02-16 06:01

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

查看更多
劫难
3楼-- · 2020-02-16 06:09

You can use {php} tags

Method 1 (won't work in Smarty 3.1 or later):

{php}

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

{/php}

Method 2:

{$var|@print_r}

Method 3:

{$var|@var_dump}
查看更多
Bombasti
4楼-- · 2020-02-16 06:09

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

查看更多
劳资没心,怎么记你
5楼-- · 2020-02-16 06:09

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

查看更多
老娘就宠你
6楼-- · 2020-02-16 06:12

in smarty V3 you can use this

{var_dump($variable)}

查看更多
SAY GOODBYE
7楼-- · 2020-02-16 06:14

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

查看更多
登录 后发表回答