splitted twig templates in multiple files

This commit is contained in:
julien
2026-02-22 19:48:40 +01:00
parent 76134c9e40
commit 6ef1eb9508
9 changed files with 38 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ return function (App $app) {
/** @var Twig $view */
$view = $request->getAttribute('view');
return $view->render($response, 'admin.twig', ['posts' => $posts]);
return $view->render($response, 'pages/admin.twig', ['posts' => $posts]);
});
// -------------------------------------------------
@@ -46,7 +46,7 @@ return function (App $app) {
/** @var Twig $view */
$view = $request->getAttribute('view');
return $view->render($response, 'post_form.twig', [
return $view->render($response, 'macros/post_form.twig', [
'action' => $id ? "/admin/edit/{$id}" : "/admin/create",
'post' => $post,
]);

View File

@@ -17,6 +17,6 @@ return function (App $app) {
/** @var Twig $view */
$view = $request->getAttribute('view'); // <-- récupération correcte
return $view->render($response, 'posts.twig', ['posts' => $posts]);
return $view->render($response, 'pages/posts.twig', ['posts' => $posts]);
});
};

View File

@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>{% block title %}Mon Blog{% endblock %}</title>
{# <link rel="stylesheet" href="/css/main.css"> #}
<style>
body {font-family: Arial, sans-serif; margin: 2rem;}
.post {border-bottom: 1px solid #ccc; padding: 1rem 0;}
@@ -11,11 +12,21 @@
</style>
</head>
<body>
<h1>
<a href="/">Mon Blog</a> |
<a href="/admin">Admin</a>
</h1>
{% block content %}{% endblock %}
</body>
</html>
{# Header commun #}
{% include 'partials/_header.twig' %}
{# Zone principale chaque page injecte son contenu #}
<main>
{% block content %}{% endblock %}
</main>
{# Footer commun #}
{% include 'partials/_footer.twig' %}
{# Scripts globaux #}
<script src="/js/app.js"></script>
{% block scripts %}{% endblock %}</body>
</html>

4
views/pages/home.twig Normal file
View File

@@ -0,0 +1,4 @@
{% extends "layout.twig" %}
{% block title %}Mon Blog{% endblock %}
{% block content %}
{% endblock %}

View File

@@ -0,0 +1,7 @@
<footer class="site-footer">
<p>&copy; {{ "now"|date("Y") }} Mon Blog Tous droits réservés.</p>
<nav>
<a href="">À propos</a> |
<a href="">Contact</a>
</nav>
</footer>

View File

@@ -0,0 +1,6 @@
<header>
<h1>
<a href="/">Mon Blog</a> |
<a href="/admin">Admin</a>
</h1>
</header>