Debug Twig (I don't have config.yml)

I am returning to PHP game after ... a long time. I am looking at Twig and I need to know more about what's going on. I found some text that should go into my config.yml file. Caveat: this is not on my system. Is this coming with the release of Twig or do I need to install Symfony? Lost here.


EDIT: I just need {{dump (var)}} to work. The httpd error log tells me: PHP Fatal error: Throw exception "Twig_Error_Syntax" with message "Function" dump "does not exist in

I install the Twig environment like this:

$twig = new Twig_Environment( $loader, array(
    'cache' => '/tmp',
    'debug' => true



source to share

1 answer

You need to make sure you are running twig version 1.5 or newer. It looks like you are missing 1 part adding a debug extension to your flag environment.

$twig->addExtension(new Twig_Extension_Debug());


Here is the documentation for the dump function:

The dump function is not available by default. You must add the Twig_Extension_Debug extension explicitly when creating the Twig environment:

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


Even if enabled, the dump function will not display anything unless the environment debug option is enabled (to avoid leaking debug information on the production server).



All Articles