Sphinx uses the Jinja templating engine for its HTML templates. Jinja is a text-based engine, and inspired by Django templates, so anyone having used Django will already be familiar with it. It also has excellent documentation for those who need to make themselves familiar with it.
No. You have several other options:
The default templating language in Sphinx is Jinja. It’s Django/Smarty inspired and easy to understand. The most important concept in Jinja is template inheritance, which means that you can overwrite only specific blocks within a template, customizing it while also keeping the changes at a minimum.
To customize the output of your documentation you can override all the templates (both the layout templates and the child templates) by adding files with the same name as the original filename into the template directory of the folder the Sphinx quickstart generated for you.
Sphinx will look for templates in the folders of templates_path first, and if it can’t find the template it’s looking for there, it falls back to the builtin templates that come with Sphinx.
A template contains variables, which are replaced with values when the template is evaluated, tags, which control the logic of the template and blocks which are used for template inheritance.
Sphinx provides base templates with a couple of blocks it will fill with data. The default templates are located in the templates folder of the Sphinx installation directory. Templates with the same name in the templates_path override templates located in the builtin folder.
For example, to add a new link to the template area containing related links all you have to do is to add a new template called layout.html with the following contents:
{% extends "!layout.html" %}
{% block rootrellink %}
<li><a href="http://project.invalid/">Project Homepage</a> »</li>
{{ super() }}
{% endblock %}
By prefixing the name of the extended template with an exclamation mark, Sphinx will load the builtin layout template. If you override a block, you should call {{ super() }} somewhere to render the block’s content in the extended template – unless you don’t want that content to show up.
The following blocks exist in the layout template:
This block contains the list of related links (the parent documents on the left, and the links to index, modules etc. on the right). relbar1 appears before the document, relbar2 after the document. By default, both blocks are filled; to show the relbar only before the document, you would override relbar2 like this:
{% block relbar2 %}{% endblock %}
A possible location for a sidebar. sidebar1 appears before the document and is empty by default, sidebar2 after the document and contains the default sidebar. If you want to swap the sidebar location override this and call the sidebar helper:
{% block sidebar1 %}{{ sidebar() }}{% endblock %}
{% block sidebar2 %}{% endblock %}
(The sidebar2 location for the sidebar is needed by the sphinxdoc.css stylesheet, for example.)
Inside templates you can set a couple of variables used by the layout template using the {% set %} tag:
Overriding works like this:
{% extends "!layout.html" %}
{% set reldelim1 = ' >' %}
Sphinx provides various Jinja functions as helpers in the template. You can use them to generate links or output multiply used elements.
These global variables are available in every template and are safe to use. There are more, but most of them are an implementation detail and might change in the future.
The next document for the navigation. This variable is either false or has two attributes link and title. The title contains HTML markup. For example, to generate a link to the next page, you can use this snippet:
{% if next %}
<a href="{{ next.link|e }}">{{ next.title }}</a>
{% endif %}