如何像在 PHP var_dump() 中一样在 Smarty 中调试变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2431763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Debug Variables in Smarty like in PHP var_dump()
提问by streetparade
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.
我在模板中有一些变量,我不知道我在哪里分配了它们。我需要知道特定变量中的内容;例如,假设我在 smarty 中有一个名为member. 我试过了,{debug}但没有用,也没有显示弹出窗口。
How can I output/debug smarty variables using something like var_dump()inside the templates?
如何使用var_dump()模板内部的东西输出/调试 smarty 变量?
回答by pinaki
You can use {php}tags
你可以使用{php}标签
Method 1 (won't work in Smarty 3.1 or later):
方法 1(不适用于 Smarty 3.1 或更高版本):
{php}
$var =
$this->get_template_vars('var');
var_dump($var);
{/php}
Method 2:
方法二:
{$var|@print_r}
Method 3:
方法三:
{$var|@var_dump}
回答by Tom Haigh
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.
数组需要@ 才能使修饰符对整个事物进行智能运行,否则它会为每个元素执行此操作。
回答by Chris
For what it's worth, you can do {$varname|@debug_print_var}to get a var_dump()-esque output for your variable.
对于它的价值,您可以为您的变量{$varname|@debug_print_var}获取var_dump()-esque 输出。
回答by david
just use {debug} in your .tpl and look at your sourcecode
只需在您的 .tpl 中使用 {debug} 并查看您的源代码
回答by Alexander Zakusilo
In new Smarty it is:
在新的 Smarty 中,它是:
<pre>
{var_dump($variable)}
</pre>
回答by karadayi
Try out with the Smarty Session:
尝试使用 Smarty 会话:
{$smarty.session|@debug_print_var}
or
或者
{$smarty.session|@print_r}
To beautify your output, use it between <pre> </pre>tags
要美化您的输出,请在<pre> </pre>标签之间使用它
回答by Bastilol
If you want something prettier I would advise
如果你想要更漂亮的东西,我会建议
{"<?php\n$data =\n"|@cat:{$yourvariable|@var_export:true|@cat:";\n?>"}|@highlight_string:true}
just replace yourvariableby your variable
只需用您的变量替换yourvariable
回答by Awais fiaz
in smarty V3 you can use this
在 smarty V3 中,您可以使用它
{var_dump($variable)}
{var_dump($variable)}
回答by Aurelink
To debug in smarty in prestashop 1.6.x :
在 prestashop 1.6.x 中以 smarty 进行调试:
{ddd($variable)} -> debug and die
{ppp($variable)} -> debug only
An onther usefull debug tag :
另一个有用的调试标签:
{debug}
回答by RubyDubee
try this .... Set $debuggingto TRUE in Smarty.
试试这个......$debugging在Smarty中设置为TRUE。

