Slim/twig-view 3.0.0 in Slim 4

Hi all,

is any example how i use slim/twig-view": “^3.0” in slim 4?

I tried hard but in the end…

settings.php

return function (ContainerBuilder $containerBuilder) {
    // Global Settings Object
    $containerBuilder->addDefinitions([
        'settings' => [
            'displayErrorDetails' => true, // Should be set to false in production
            'logger' => [
                'name' => 'slim-app',
                'path' => isset($_ENV['docker']) ? 'php://stdout' : __DIR__ . '/../logs/app.log',
                'level' => Logger::DEBUG,
            ],
            'twig' => [
                'path_templates' => __DIR__ . '/../src/Views',
                'path_cache' => __DIR__ . '/../var/cache/views'
            ]
        ],
    ]);
};

dependencies.php

// Twig Template System
    // Register component on container
    $containerBuilder->addDefinitions([
        'view' => function (ContainerInterface $c) {
            $settings       = $c->get('settings');
            $twigSettings   = $settings['twig'];

            $loader = new \Twig\Loader\FilesystemLoader(
                $twigSettings['path_templates']
            );
            $options = [
                'cache' => $twigSettings['path_cache']
            ];

            $view = new \Twig\Environment(
                $loader, $options
            );

            return $view;
    },
    ]);

routes.php

$app->get('/magnotta', function (Request $request, Response $response, $args) {
    $result = $this->get('view')->render(
            'profile.html', [
            'name' => 'magnotta'
    ]);
    $this->get('logger')->info('magnotta');

    $response->getBody()->write($result);

    return $response;
});

i have this code, but in this i have error

use DI\Container;

use Slim\Factory\AppFactory;
use Slim\Middleware\ErrorMiddleware;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;

require __DIR__ .'/vendor/autoload.php';

$container = new Container();
AppFactory::setContainer($container);

$app = AppFactory::create();

$errorMiddleware = new ErrorMiddleware(
    $app->getCallableResolver(),
    $app->getResponseFactory(),
    true,
    false,
    false
);

$app->add($errorMiddleware);

$loader = new \Twig\Loader\FilesystemLoader('views');

$twig = new Twig($loader, [
    'cache' => false
    ]);

$twigMiddleware = new TwigMiddleware($twig, $app->getRouteCollector()->getRouteParser(), '/');

$app->add($twigMiddleware);

$app->get('/', function (Request $request, Response $response) {

    return $this->get('view')->render($response, 'home.twig');
});

$app->run();