Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig debugging (I have no config.yml)

I'm getting back into the PHP game after... a long time. I'm looking at Twig, and need to see more of what's going on. I've found some text that needs to go into my config.yml file. Caveat: it's not on my system. Does it come w/ the Twig release or do I have to install Symfony as well? Kind of lost here.

Cheers.

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

I'm setting my Twig environment like so:

$twig = new Twig_Environment( $loader, array(
    'cache' => '/tmp',
    'debug' => true
));
like image 862
kiss-o-matic Avatar asked Dec 01 '25 07:12

kiss-o-matic


1 Answers

You need to make sure that you are using twig version 1.5 or later. It looks like you are only missing 1 piece adding the debug extension to your twig environment.

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

Here is the documentation for the dump function:

http://twig.sensiolabs.org/doc/functions/dump.html

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

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

Even when enabled, the dump function won't display anything if the debug option on the environment is not enabled (to avoid leaking debug information on a production server).

like image 194
Chase Avatar answered Dec 03 '25 20:12

Chase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!