NEW FEATURE: titles

This commit is contained in:
Jeroen De Meerleer 2021-08-05 14:46:20 +02:00
parent 025808bbcf
commit b9e55c554f
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 9 additions and 3 deletions

View File

@ -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']);
}
}

View File

@ -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';
}

View File

@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jeroen De Meerleer :: {% block title %}{% endblock %}</title>
<title>Jeroen De Meerleer{% if block("title") is not empty %} :: {% block title %}{% endblock %}{% endif %}</title>
{% block styles %}{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.html.twig" %}
{% block title %}{{ pagetitle }}{% endblock %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<header>{{ header | markdown | raw }}</header>
<main>{{ content | markdown | raw }}</main>