Twig Debug mode

Hi,
How can I turn on Twig’s debug mode so I can use the dump function?

Thanks!

Following from the example in the guides you can do the following:

<?php
// Create app
$app = new \Slim\App();

// Get container
$container = $app->getContainer();

// Register component on container
$container['view'] = function ($container) {
    $view = new \Slim\Views\Twig('path/to/templates', [
        'debug' => true, // This line should enable debug mode
        'cache' => 'path/to/cache'
    ]);
    $view->addExtension(new \Slim\Views\TwigExtension(
        $container['router'],
        $container['request']->getUri()
    ));
    
    // This line should allow the use of {{ dump() }}
    $view->addExtension(new \Twig_Extension_Debug());

    return $view;
};
1 Like