Add custom templates $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#add-custom-templates">
Add, extend, or overrde Jinja2 templates.
Create a directory in your Sphinx project and add it to your Sphinx configuration:
templates_path = ["_templates"]
See also
Extend templates $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#extend-templates" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#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 $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#extend-template-blocks" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#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.
{% extends "!page.html" %}
{{ super() }}
{% block extrahead %}
{# Included before the closing </head> tag #}
{% endblock %}
{% block extrabody %}
{# Included after the main content, before the <footer> #}
{% endblock %}
Add custom templates $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#id1" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#id1'">
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 $el.setAttribute('data-tooltip', 'Copy link to this element'), 2000)" aria-label="Copy link to this element" class="headerlink" data-tooltip="Copy link to this element" href="#available-templates" x-intersect.margin.0%.0%.-70%.0%="activeSection = '#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.