.. _templates:
Templates
=========
Spirit templates can be overridden the regular
`Django way `_.
The issue with overriding is keeping up with all the changes a new Spirit
version may introduce to those templates. To avoid this, Spirit has some specific
templates that can be safely overridden.
.. _extend_the_html_head_section:
Extend the HTML head section
----------------------------
Extending the head section is the best way to override the CSS style,
add JS scripts, add some font, etc.
Let's override the theme colors to make it green-ish::
{# templates/spirit/_base.html #}
{% extends "spirit/_base.html" %}
{% block custom_head_extra %}
{% endblock %}
The ``templates`` folder must be next to the ``static`` and ``media``
folders.
There is a bunch more of CSS color variables in the
`Sass colors file `_.
There is also a dark-mode that is active when the OS is in dark-mode, but
it can be set as the default or as the only theme the same way.
Extend other sections
---------------------
The HTML body can be extended as well, before and after
the Spirit layout section. This is useful to add an extra nav-bar
at the top, or to add some JS snippet or footer at the bottom.
Let's just add some minimal text this time::
{# templates/spirit/_base.html #}
{% extends "spirit/_base.html" %}
{% block custom_before_spirit_body %}
My extra nav bar
{% endblock %}
{% block custom_after_spirit_body %}
My extra footer
{% endblock %}
I've inlined the ``style`` in the elements, but a better way is to style things
in the head section, see :ref:`extend_the_html_head_section`.
Customize the site name/logo
----------------------------
The forum name can be set without overriding any template,
go to ``http://127.0.0.1:8000/st/admin/config/``, and change
the ``site name`` field.
The template can be overridden to include custom HTML,
such as an image::
{# templates/spirit/_header.html #}
{% extends "spirit/_header.html" %}
{% block custom_header_logo %}
MyForum
{% endblock %}