first commit
This commit is contained in:
30
views/admin.twig
Normal file
30
views/admin.twig
Normal file
@@ -0,0 +1,30 @@
|
||||
{% extends "layout.twig" %}
|
||||
|
||||
{% block title %}Admin – Gestion des articles{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Gestion des articles</h2>
|
||||
|
||||
<!-- Lien d’ajout -->
|
||||
<a href="/admin/edit/0">+ Ajouter un article</a>
|
||||
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<h3>{{ post.title }}</h3>
|
||||
<p>{{ post.content|nl2br }}</p>
|
||||
|
||||
<div class="admin-actions">
|
||||
<a href="/admin/edit/{{ post.id }}">Éditer</a>
|
||||
|
||||
<form method="post" action="/admin/delete/{{ post.id }}" style="display:inline;">
|
||||
<button type="submit"
|
||||
onclick="return confirm('Supprimer cet article ?')">
|
||||
Supprimer
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>Aucun article à gérer.</p>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
21
views/layout.twig
Normal file
21
views/layout.twig
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{% block title %}Mon Blog{% endblock %}</title>
|
||||
<style>
|
||||
body {font-family: Arial, sans-serif; margin: 2rem;}
|
||||
.post {border-bottom: 1px solid #ccc; padding: 1rem 0;}
|
||||
.admin-actions a,
|
||||
.admin-actions form {margin-right: .5rem;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
<a href="/">Mon Blog</a> |
|
||||
<a href="/admin">Admin</a>
|
||||
</h1>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
31
views/post_form.twig
Normal file
31
views/post_form.twig
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
{% extends "layout.twig" %}
|
||||
|
||||
{% block title %}
|
||||
{% if post is defined %}Éditer l’article{% else %}Créer un article{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>
|
||||
{% if post is defined %}Éditer{% else %}Créer{% endif %} un article
|
||||
</h2>
|
||||
|
||||
<form method="post" action="{{ action }}">
|
||||
<p>
|
||||
<label>Titre<br>
|
||||
<input type="text" name="title"
|
||||
value="{{ post.title|default('') }}" required>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>Contenu<br>
|
||||
<textarea name="content" rows="6" required>{{ post.content|default('') }}</textarea>
|
||||
</label>
|
||||
</p>
|
||||
<button type="submit">
|
||||
{% if post is defined %}Mettre à jour{% else %}Enregistrer{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p><a href="/admin">Retour à l’admin</a></p>
|
||||
{% endblock %}
|
||||
14
views/posts.twig
Normal file
14
views/posts.twig
Normal file
@@ -0,0 +1,14 @@
|
||||
{% extends "layout.twig" %}
|
||||
|
||||
{% block title %}Articles{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<h2>{{ post.title }}</h2>
|
||||
<p>{{ post.content|nl2br }}</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>Aucun article publié.</p>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user