Twig: adding twig extension debug from config file

纵饮孤独 提交于 2020-01-30 06:05:58

问题


According to TWIG documentation, in order to use the dump function I should first add the extension debug like so:

$twig = new Twig_Environment($loader, array(
'debug' => true,
// ...
 ));
$twig->addExtension(new Twig_Extension_Debug());

But how do I do that from config.yml ? I use symfony2.


回答1:


It should be defined as follow,

# app/config/config.yml
services:
    custom.twig.extension.debug:
        class: Twig_Extension_Debug
        tags:
             - { name: 'twig.extension' }


来源:https://stackoverflow.com/questions/18362495/twig-adding-twig-extension-debug-from-config-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!