简体   繁体   English

打印Smarty模板中可用的所有变量

[英]Print all variables available in a Smarty template

How do you print all variables available in the context of a Smarty template? 如何在Smarty模板的上下文中打印所有可用变量? Something like the Django debug trace that lists everything being passed. 类似于Django调试跟踪,列出了传递的所有内容。

Thanks 谢谢

Use {debug} From the manual : 使用{debug} 来自手册

{debug} dumps the debug console to the page. {debug}将调试控制台转储到页面。 This works regardless of the debug settings in the php script. 无论php脚本中的调试设置如何,这都有效。 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 必须在您的设置或类中启用$debugging = true ,并且必须取消阻止站点弹出窗口以查看窗口

var_dump($Smarty->_tpl_vars);

来自Smarty代码:)

Updated answer for Smarty 3: getTemplateVars 更新了Smarty 3: getTemplateVars的答案

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

$all_tpl_vars = $smarty->getTemplateVars(); $ all_tpl_vars = $ smarty-> getTemplateVars(); var_dump($all_tpl_vars); 后续代码var_dump($ all_tpl_vars);

//before pushing to the template //在推送到模板之前

exit; 出口;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM