Twig dump isn't printing anything

1.7k views Asked by At

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

There are 1 answers

2
Wouter J On BEST ANSWER

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.