Twig dump isn't printing anything

泄露秘密 提交于 2019-12-10 20:51:23

问题


I am a little bit confused right now. I always used the twig dump function like any other twig function but now it has absolutely no output. No errors/exceptions, just nothing. Everything else is working fine, like the trans filter.

{{ dump('test') }} # prints nothing
{{ 'layout.booking.chooseArea'|trans }} # prints the translated message

Right now this template doesn't contain anything more than that. The dump also doesn't work in the parent template or in base.html.twig.

Again, the dump prints nothing: not an empty string, not null, not a single pixel on the screen.

Any ideas what could cause this?

Symfony version: 2.6.x-dev

update

{{ dump('test') }} # doesn't work (anymore?)
{% dump('test') %} # does (still) work

Has this been removed or something? Why are there no errors? By the way... debug flag is set.


回答1:


In Symfony 2.6, there is a new VarDumper component and DebugBundle. These override twig's dump() function to give a lot more and nicer dump output.

However, you have to register the DebugBundle in your AppKernel, otherwise it'll just ignore the call. To do this, you should add this to app/AppKernel.php:

// app/AppKernel.php

// ...
public function registerBundles()
{
    // ...

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        // ...
    }

    return $bundles;
}

Please note that this new dump function will dump the output in the web dev toolbar, to avoid screwing up the page layout.

In 2.6.0, this will be fixed by having a fallback to the native twig dump() function why the DebugBundle is not registered.



来源:https://stackoverflow.com/questions/26915293/twig-dump-isnt-printing-anything

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