How to inject twig?

Hello,

With Slim 4, and slim/twig-view 3.0

I setup Twig like that:

$container->set('view', function($container) {
  $settings = $container->get('settings');
  $twigSettings = $settings['twig'];
  $root = dirname(__DIR__);
  return  Twig::create($twigSettings['path'], [
    'cache' => $twigSettings['cache']
  ]);
});

And In my controller, I do:

public function __construct(Container $container, ...) {
  ...
}

public function foo(Request $request, Response $response, $args): Response {
  ...
  $this->container->get('view')->render($response, 'mytemplate.twig');

The reason why I inject the container is because I have to do container->get(‘view’)

I’ve tried:
$container->set(Twig::class, function($container) {
and
public function __construct(Twig $twig, ...) {

But it does not work :frowning:

Actually, I can do:

$container->set('view', function($container) {
  ...
  return  Twig::create(....)
});
$container->set(Twig::class, function($container) {
  return $container->get('view');
});

But it is uggly ?