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;