From 82f3163ff57e1365e8e2c31e7da65952848cba12 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 10 Jun 2022 15:54:31 +0100 Subject: [PATCH] Derive body class for pages --- templates/base.html | 4 +--- templates/wagtail_base.html | 5 +++++ website/common/models.py | 4 ++++ website/home/templates/home/home_page.html | 5 +---- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 templates/wagtail_base.html diff --git a/templates/base.html b/templates/base.html index dd7e913..4a8e2dc 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,9 +5,7 @@ - {% block title %} - {% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %} - {% endblock %} + {% block title %}{% endblock %} {% block title_suffix %} {% wagtail_site as current_site %} {% if current_site and current_site.site_name %}:: {{ current_site.site_name }}{% endif %} diff --git a/templates/wagtail_base.html b/templates/wagtail_base.html new file mode 100644 index 0000000..72dec7c --- /dev/null +++ b/templates/wagtail_base.html @@ -0,0 +1,5 @@ +{% extends "base.html" %} + +{% block body_class %}{{ page.body_class }}{% endblock %} + +{% block title %}{% if page.seo_title %}{{ page.seo_title }}{% else %}{{ page.title }}{% endif %}{% endblock %} diff --git a/website/common/models.py b/website/common/models.py index 8ee8382..1244229 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -6,3 +6,7 @@ from wagtail.models import Page class BasePage(Page): class Meta: abstract = True + + @property + def body_class(self): + return "page-" + self._meta.db_table.replace("_", "-") diff --git a/website/home/templates/home/home_page.html b/website/home/templates/home/home_page.html index e11350e..78963a1 100644 --- a/website/home/templates/home/home_page.html +++ b/website/home/templates/home/home_page.html @@ -1,7 +1,4 @@ -{% extends "base.html" %} -{% load static %} - -{% block body_class %}template-homepage{% endblock %} +{% extends "wagtail_base.html" %} {% block content %}