Twig dump isn't printing anything

2019-07-03 22:10发布

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条回答
姐就是有狂的资本
2楼-- · 2019-07-03 22:41

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.

查看更多
登录 后发表回答