From b9e55c554fd141e27754e9c41dd48ab6639e1fc2 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 5 Aug 2021 14:46:20 +0200 Subject: [PATCH] NEW FEATURE: titles --- src/Controller/DefaultController.php | 5 ++++- src/Repository/Page.php | 3 +++ templates/base.html.twig | 2 +- templates/page.html.twig | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index daf94bd..576bad5 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -15,6 +15,9 @@ class DefaultController extends Controller { $pageRepo = new Page(); $page = $pageRepo->getPage($page); - return $this->render('/page.html.twig', ['header' => $page['header'], 'content' => $page['content']], $page['status']); + return $this->render('/page.html.twig', [ + 'header' => $page['header'], + 'content' => $page['content'], + 'title' => $page['title']], $page['status']); } } \ No newline at end of file diff --git a/src/Repository/Page.php b/src/Repository/Page.php index e282483..637068b 100644 --- a/src/Repository/Page.php +++ b/src/Repository/Page.php @@ -22,10 +22,13 @@ class Page public function getPage(string $page) { $return['header'] = file_get_contents(strtolower($this->root . '/_main.md')); + $titles = json_decode(file_get_contents($this->root . '/titles.json'), true); if(file_exists($this->root . '/' . $page . '.md')) { + $return['title'] = $titles[$page] ?? ''; $return['content'] = file_get_contents(strtolower($this->root . '/' . $page . '.md')); $return['status'] = '200'; } else { + $return['title'] = $titles['404'] ?? ''; $return['content'] = file_get_contents(strtolower($this->root . '/404.md')); $return['status'] = '404'; } diff --git a/templates/base.html.twig b/templates/base.html.twig index 4dd955a..25e6dc6 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -3,7 +3,7 @@ - Jeroen De Meerleer :: {% block title %}{% endblock %} + Jeroen De Meerleer{% if block("title") is not empty %} :: {% block title %}{% endblock %}{% endif %} {% block styles %}{% endblock %} diff --git a/templates/page.html.twig b/templates/page.html.twig index a386a28..f29a1c5 100644 --- a/templates/page.html.twig +++ b/templates/page.html.twig @@ -1,5 +1,5 @@ {% extends "base.html.twig" %} -{% block title %}{{ pagetitle }}{% endblock %} +{% block title %}{{ title }}{% endblock %} {% block content %}
{{ header | markdown | raw }}
{{ content | markdown | raw }}