Add templates

This commit is contained in:
Dave Smith-Hayes 2024-05-15 22:03:49 -04:00
parent e038467a4b
commit c1d2651879
7 changed files with 62 additions and 6 deletions

View File

@ -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));
}
/**

View File

@ -0,0 +1,14 @@
<?php
namespace Slovocast\Controller;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class HomePage extends Controller
{
public function respond(Request $request, Response $response): Response
{
return $this->render('home');
}
}

View File

@ -9,6 +9,6 @@ class RegisterUserAction extends Controller
{
public function respond(): Response
{
return $this->respond('user/register/success');
return $this->respond('users/register/success');
}
}

View File

@ -9,6 +9,6 @@ class RegisterUserPage extends Controller
{
public function respond(): Response
{
return $this->render('user/register');
return $this->render('users/register');
}
}

7
code/templates/home.twig Normal file
View File

@ -0,0 +1,7 @@
{% extends 'layouts/skeleton' %}
{% block "content" %}
<div>
<h1>Slovocast</h1>
</div>
{% endblock %}

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block "page_title" %}{% endblock %}</title>
</head>
<body>
<div class="container">
<header>
{% block "header" %}{% endblock %}
</header>
<main>
{% block "content" %}{% endblock %}
</main>
<footer>
{% blcok "footer" %}{% endblock %}
</footer>
</div>
</body>
</html>

View File

@ -0,0 +1,10 @@
{% extends 'layouts/skeleton' %}
{% block "content" %}
<div>
<form action="/users/register" method="post">
<input type="submit" label="Submit">
</form>
</div>
{% endblock %}