From a5619e2307bf95a5629f7f75fe08bf3296d3cdb3 Mon Sep 17 00:00:00 2001 From: tim Date: Sat, 23 Dec 2023 23:56:18 +0100 Subject: [PATCH] Refactor templates to be more structured --- src/Controller/SnipController.php | 2 +- templates/base/base.html.twig | 16 ++-------------- templates/base/container.html.twig | 8 ++++++++ templates/base/single.column.html.twig | 10 ++++++++++ templates/form.html.twig | 6 ------ templates/generic/form.html.twig | 7 +++++++ templates/generic/simple.html.twig | 5 +++++ templates/security/login.html.twig | 5 ++--- templates/security/register.html.twig | 5 ++--- templates/simple.html.twig | 5 ----- templates/snip/edit.html.twig | 5 ++--- templates/snip/index.html.twig | 5 +---- templates/snip/single.html.twig | 4 ++-- templates/user/profile.html.twig | 6 +++--- templates/version/index.html.twig | 2 +- 15 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 templates/base/container.html.twig create mode 100644 templates/base/single.column.html.twig delete mode 100644 templates/form.html.twig create mode 100644 templates/generic/form.html.twig create mode 100644 templates/generic/simple.html.twig delete mode 100644 templates/simple.html.twig diff --git a/src/Controller/SnipController.php b/src/Controller/SnipController.php index e4fa3e7..9b52e28 100644 --- a/src/Controller/SnipController.php +++ b/src/Controller/SnipController.php @@ -132,7 +132,7 @@ class SnipController extends AbstractController return $this->redirectToRoute('snip_index'); } - return $this->render('form.html.twig', [ + return $this->render('generic/form.html.twig', [ 'message' => sprintf('Do you really want to delete "%s"?', $snip), 'form' => $form->createView(), ]); diff --git a/templates/base/base.html.twig b/templates/base/base.html.twig index 043db66..cd1d24d 100644 --- a/templates/base/base.html.twig +++ b/templates/base/base.html.twig @@ -3,7 +3,7 @@ - {% block title %}SNIPS{% endblock %} + {% if title is defined %}{{ title }}{% else %}SNIPS{% endif %} {% block css %} @@ -37,19 +37,7 @@ {# body blocks #} -{% block bodyraw %} -
-
-
- {% block body %}{% endblock %} -
- {% if block('body2') is defined %} -
- {{ block('body2') }} -
- {% endif %} -
-
+{% block content %} {% endblock %} {# javascript block #} diff --git a/templates/base/container.html.twig b/templates/base/container.html.twig new file mode 100644 index 0000000..3eb0f5a --- /dev/null +++ b/templates/base/container.html.twig @@ -0,0 +1,8 @@ +{% extends 'base/base.html.twig' %} + +{% block content %} +
+ {% block container %} + {% endblock %} +
+{% endblock %} diff --git a/templates/base/single.column.html.twig b/templates/base/single.column.html.twig new file mode 100644 index 0000000..58b4b39 --- /dev/null +++ b/templates/base/single.column.html.twig @@ -0,0 +1,10 @@ +{% extends 'base/container.html.twig' %} + +{% block container %} +
+
+ {% if title is defined %}

{{ title }}

{% endif %} + {% block body %}{% endblock %} +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/form.html.twig b/templates/form.html.twig deleted file mode 100644 index 1b8e7eb..0000000 --- a/templates/form.html.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends 'base/base.html.twig' %} - -{% block body %} -

{{ message }}

- {{ form(form) }} -{% endblock %} \ No newline at end of file diff --git a/templates/generic/form.html.twig b/templates/generic/form.html.twig new file mode 100644 index 0000000..cf9f998 --- /dev/null +++ b/templates/generic/form.html.twig @@ -0,0 +1,7 @@ +{% extends 'base/single.column.html.twig' %} + +{% set title %}{{ message }}{% endset %} + +{% block body %} + {{ form(form) }} +{% endblock %} \ No newline at end of file diff --git a/templates/generic/simple.html.twig b/templates/generic/simple.html.twig new file mode 100644 index 0000000..0ce1bee --- /dev/null +++ b/templates/generic/simple.html.twig @@ -0,0 +1,5 @@ +{% extends 'base/single.column.html.twig' %} + +{% block body %} + {{ text | nl2br }} +{% endblock %} \ No newline at end of file diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index 53f81fb..a39e98a 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -1,6 +1,6 @@ -{% extends 'base/base.html.twig' %} +{% extends 'base/single.column.html.twig' %} -{% block title %}Login{% endblock %} +{% set title %}Login{% endset %} {% block body %}
@@ -12,7 +12,6 @@ You are already logged in as {{ app.user }}, Logout {% endif %} -

Please login

diff --git a/templates/security/register.html.twig b/templates/security/register.html.twig index 002321e..113c52c 100644 --- a/templates/security/register.html.twig +++ b/templates/security/register.html.twig @@ -1,8 +1,7 @@ -{% extends 'base/base.html.twig' %} +{% extends 'base/single.column.html.twig' %} -{% block title %}Register{% endblock %} +{% set title %}Register{% endset %} {% block body %} -

Register new user

{{ form(registrationForm) }} {% endblock %} \ No newline at end of file diff --git a/templates/simple.html.twig b/templates/simple.html.twig deleted file mode 100644 index 3039167..0000000 --- a/templates/simple.html.twig +++ /dev/null @@ -1,5 +0,0 @@ -{% extends 'base/base.html.twig' %} - -{% block body %} - {{ text | nl2br }} -{% endblock %} \ No newline at end of file diff --git a/templates/snip/edit.html.twig b/templates/snip/edit.html.twig index 690b0ff..a466daf 100644 --- a/templates/snip/edit.html.twig +++ b/templates/snip/edit.html.twig @@ -1,6 +1,6 @@ -{% extends 'base/base.html.twig' %} +{% extends 'base/single.column.html.twig' %} -{% block title %}Edit {{ snip }}{% endblock %} +{% set title %}Edit {{ snip }}{% endset %} {% block body %} {% if snip.id %} @@ -13,6 +13,5 @@ Index

-

Editing {{ snip }}

{{ form(form) }} {% endblock %} \ No newline at end of file diff --git a/templates/snip/index.html.twig b/templates/snip/index.html.twig index 221109a..0a750ab 100644 --- a/templates/snip/index.html.twig +++ b/templates/snip/index.html.twig @@ -1,9 +1,6 @@ -{% extends 'base/base.html.twig' %} - -{% block title %}{{ title }}{% endblock %} +{% extends 'base/single.column.html.twig' %} {% block body %} -

{{ title }}

Add diff --git a/templates/snip/single.html.twig b/templates/snip/single.html.twig index e86d88d..edc4534 100644 --- a/templates/snip/single.html.twig +++ b/templates/snip/single.html.twig @@ -1,6 +1,6 @@ -{% extends 'base/base.html.twig' %} +{% extends 'base/single.column.html.twig' %} -{% block title %}Snip {{ snip }}{% endblock %} +{% set title %}Snip {{ snip }}{% endset %} {% block body %} diff --git a/templates/user/profile.html.twig b/templates/user/profile.html.twig index b22a57d..8027bab 100644 --- a/templates/user/profile.html.twig +++ b/templates/user/profile.html.twig @@ -1,9 +1,9 @@ -{% extends "base/base.html.twig" %} +{% extends 'base/single.column.html.twig' %} {% block body %}
-

{{ app.user.name }}

+

{{ app.user.name }}


{% if is_granted('ROLE_ADMIN') %}

@@ -16,7 +16,7 @@ {% endif %}
-

Change profile

+

Change profile

{{ form(form) }}
diff --git a/templates/version/index.html.twig b/templates/version/index.html.twig index aeeaced..6b57c41 100644 --- a/templates/version/index.html.twig +++ b/templates/version/index.html.twig @@ -1,4 +1,4 @@ -{% extends 'base/base.html.twig' %} +{% extends 'base/single.column.html.twig' %} {% block title %}Snip {{ snip }}{% endblock %}