From c1d265187996c8a53fe0407e9198e402f5eb60da Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Wed, 15 May 2024 22:03:49 -0400 Subject: [PATCH] Add templates --- code/src/Bootstrap.php | 12 +++++++---- code/src/Controller/HomePage.php | 14 +++++++++++++ .../Controller/User/RegisterUserAction.php | 2 +- code/src/Controller/User/RegisterUserPage.php | 2 +- code/templates/home.twig | 7 +++++++ code/templates/layouts/skeleton.twig | 21 +++++++++++++++++++ code/templates/users/register.twig | 10 +++++++++ 7 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 code/src/Controller/HomePage.php create mode 100644 code/templates/home.twig create mode 100644 code/templates/layouts/skeleton.twig create mode 100644 code/templates/users/register.twig diff --git a/code/src/Bootstrap.php b/code/src/Bootstrap.php index ce0490a..2f366d8 100644 --- a/code/src/Bootstrap.php +++ b/code/src/Bootstrap.php @@ -7,6 +7,9 @@ use Slim\Factory\AppFactory; use League\Config\Configuration; use DI\Container; use DI\ContainerBuilder; +use Slim\Views\Twig; +use Slim\Views\TwigMiddleware; +use Slovocast\Routes; class Bootstrap { @@ -52,10 +55,7 @@ class Bootstrap */ protected static function establishRoutes(App $app): void { - $app->get('/', function ($req, $res) { - $res->getBody()->write(json_encode([ 'message' => "hello!" ])); - return $res->withHeader("Content-Type", "application/json"); - }); + Routes::init($app); } /** @@ -67,6 +67,10 @@ class Bootstrap protected static function establishMiddleware(App $app): void { $app->addErrorMiddleware(true, true, true); + + // Twig + $twig = Twig::create(__DIR__ . "../templates", [ 'cache' => false ]); + $app->add(TwigMiddleware::create($app, $twig)); } /** diff --git a/code/src/Controller/HomePage.php b/code/src/Controller/HomePage.php new file mode 100644 index 0000000..3081b73 --- /dev/null +++ b/code/src/Controller/HomePage.php @@ -0,0 +1,14 @@ +render('home'); + } +} diff --git a/code/src/Controller/User/RegisterUserAction.php b/code/src/Controller/User/RegisterUserAction.php index 5f3d3a6..1427209 100644 --- a/code/src/Controller/User/RegisterUserAction.php +++ b/code/src/Controller/User/RegisterUserAction.php @@ -9,6 +9,6 @@ class RegisterUserAction extends Controller { public function respond(): Response { - return $this->respond('user/register/success'); + return $this->respond('users/register/success'); } } diff --git a/code/src/Controller/User/RegisterUserPage.php b/code/src/Controller/User/RegisterUserPage.php index 02f60ce..d2943fe 100644 --- a/code/src/Controller/User/RegisterUserPage.php +++ b/code/src/Controller/User/RegisterUserPage.php @@ -9,6 +9,6 @@ class RegisterUserPage extends Controller { public function respond(): Response { - return $this->render('user/register'); + return $this->render('users/register'); } } diff --git a/code/templates/home.twig b/code/templates/home.twig new file mode 100644 index 0000000..9629149 --- /dev/null +++ b/code/templates/home.twig @@ -0,0 +1,7 @@ +{% extends 'layouts/skeleton' %} + +{% block "content" %} +
+

Slovocast

+
+{% endblock %} diff --git a/code/templates/layouts/skeleton.twig b/code/templates/layouts/skeleton.twig new file mode 100644 index 0000000..2acd9b9 --- /dev/null +++ b/code/templates/layouts/skeleton.twig @@ -0,0 +1,21 @@ + + + + {% block "page_title" %}{% endblock %} + + +
+
+ {% block "header" %}{% endblock %} +
+ +
+ {% block "content" %}{% endblock %} +
+ +
+ {% blcok "footer" %}{% endblock %} +
+
+ + diff --git a/code/templates/users/register.twig b/code/templates/users/register.twig new file mode 100644 index 0000000..11aa607 --- /dev/null +++ b/code/templates/users/register.twig @@ -0,0 +1,10 @@ +{% extends 'layouts/skeleton' %} + +{% block "content" %} +
+
+ + +
+
+{% endblock %}