I am trying to use {{ dump(something) }}
but couldn’t find how to enable the debug extension for Twig in Slim 4. All info I can find is related to 3; appreciate if someone can point me in the right direction.
You have to add the Twig DebugExtension
to use the dump
function in your Twig templates.
The dump
function will only output something if Twig runs in debug
mode.
-
Enable the Twig debug mode
-
Add the extension:
$twig->addExtension(new \Twig\Extension\DebugExtension());
- Then dump a variable using the
dump
function;
{{ dump(user) }}
1 Like
I solved the issue with modifying the containerazied approach shown on twig-view
's readme:
$container->set('view', function() {
$twig = Twig::create('../templates', ['debug' => true]);
$twig->addExtension(new \Twig\Extension\DebugExtension());
return $twig;
});