Add custom templates
Add, extend, or overrde Jinja2 templates.
Create a directory in your Sphinx project and add it to your Sphinx configuration:
See also
Extend templates
To extend existing templates, create a new file with the same name and add the following code:
{% extends "!TEMPLATE" %}
{{ super() }}
Replace TEMPLATE
with the name of the template you want to extend.
The exclamation mark lets Sphinx load the parent template from the HTML theme.
Call super()
to render the original content of the parent template.
See also
Extend template blocks
To add code, you can extend the page template and override the template blocks:
extrahead
Adds your template code before the closing
</head>
tag. This is useful to add custom styles or JavaScript code.body_before
Adds content to the top of the page.
body_after
Adds content to the bottom of the page.
Add custom templates
You can define completely custom layouts and templates for your pages.
For example, to create your own custom footer template,
create a file _templates/footer.html
with the following content:
{# A custom footer template that doesn't inherit from the parent. #}
<div style="background-color: red;">
Your custom footer.
</div>
See also
Available templates
The main templates you can extend are:
header.html
Template for the header.
footer.html
Template for the footer.
page.html
Template for the body of the page.
This page must contain the
{{ body }}
expression to render the contents of your documentation. This template extends the templatelayout.html
.layout.html
Main template defining the structure of the page, including the HTML
<head>
with all imported CSS and JavaScript files.
For more information, see the available templates in the directory src/sphinxawesome_theme.