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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/716916/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:37:02  来源:igfitidea点击:

Print all variables available in a Smarty template

phpsmarty

提问by Lorenzo

How do you print all variables available in the context of a Smarty template? Something like the Django debug trace that lists everything being passed.

如何打印 Smarty 模板上下文中可用的所有变量?类似 Django 调试跟踪的东西,它列出了所有被传递的内容。

Thanks

谢谢

回答by Aron Rotteveel

Use {debug}From the manual:

使用{debug}手册

{debug}dumps the debug console to the page. This works regardless of the debug settings in the php script. 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.

{debug}将调试控制台转储到页面。无论 php 脚本中的调试设置如何,这都有效。由于这是在运行时执行的,因此只能显示分配的变量;不是正在使用的模板。但是,您可以在模板范围内看到所有当前可用的变量。

$debugging = truemust be enabled in your settings or class, and site popups must be unblocked to see the window

$debugging = true必须在您的设置或课程中启用,并且必须取消阻止站点弹出窗口才能看到该窗口

回答by Thinker

var_dump($Smarty->_tpl_vars);

From the Smarty code :)

来自 Smarty 代码 :)

回答by John Magnolia

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();

回答by Louis Ferreira

$all_tpl_vars = $smarty->getTemplateVars(); var_dump($all_tpl_vars);

$all_tpl_vars = $smarty->getTemplateVars(); var_dump($all_tpl_vars);

//before pushing to the template

//在推送到模板之前

exit;

出口;