Twig模板引擎提供了一个调试工具。 开启调试(Enable debugging)你要开启 Twig 的调试功能是在 sites/default/services.yml 里。 设置该文件中的debug变量为 true: [backcolor=rgb(15, 25, 42) !important][size=1em]
| parameters:
twig.config:
debug: true
|
如果你用的是火狐,请确保“HTML”->“Show Comments”选项是开启(选中)的。 自动重新加载编译过的Twig模板输出变量[backcolor=rgb(15, 25, 42) !important][size=1em]
[backcolor=rgb(15, 25, 42) !important][size=1em]
如果你安装了 Devel 子模块kint,你可以在twig模板中加入以下代码以获得可折叠显示的变量: [backcolor=rgb(15, 25, 42) !important][size=1em]
以下是英文原文,可对照阅读: The Twig templating engine offers a debug tool. Enable debuggingYou enable Twig Debugging in sites/default/services.yml. Set the debug variable to true: [backcolor=rgb(15, 25, 42) !important][size=1em]
| parameters:
twig.config:
debug: true
|
In firebug make sure that "Show Comments" is enabled: Automatic reloading Twig templates are compiledTwig templates are compiled to PHP classes on disk for better performance, but this means by default your templates are not refreshed when you make changes. To enable automatic reloading of Twig templates, enable debug in services.yml. For more information, see https://drupal.org/node/1903374(link is external). Printing variables{{ dump() }}
{{ dump(var) }}
If you have Devel's kint submodule you can get an accordion display of the variables available to twig with:
|