From e86e3a12387b74a682497286a51aff7499a135dc Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sun, 22 Mar 2026 10:28:37 +0200 Subject: [PATCH] add twig to container --- bootstrap/app.php | 11 ++++++++--- bootstrap/container.php | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 20ac063..ab6b076 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -3,16 +3,21 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use DI\Bridge\Slim\Bridge; +use Slim\Views\Twig; +use Slim\Views\TwigMiddleware; $container = require __DIR__.'/container.php'; $app = Bridge::create($container); +$app->add(TwigMiddleware::create($app, $container->get(Twig::class))); + // change first param to false for production $app->addErrorMiddleware(true, true, true); -$app->get('/', function (Response $response) { - $response->getBody()->write("Hello world!"); - return $response; +$app->get('/admin', function (Response $response, Twig $twig) { + return $twig->render($response, 'admin.html.twig', [ + 'name' => 'John', + ]); }); return $app; diff --git a/bootstrap/container.php b/bootstrap/container.php index 3a35c97..a2e05f1 100644 --- a/bootstrap/container.php +++ b/bootstrap/container.php @@ -1,9 +1,13 @@ Twig::create(__DIR__.'/../views/templates', ['cache' => false]), ]); return $container;