How do you enable debug extension for Twig in Slim 4?

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.

  1. Enable the Twig debug mode

  2. Add the extension:

$twig->addExtension(new \Twig\Extension\DebugExtension());
  1. Then dump a variable using the dump function;
{{ dump(user) }}

https://twig.symfony.com/doc/3.x/functions/dump.html

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;
});