2008-03-09 16:32:24 -05:00
|
|
|
.. _templating:
|
|
|
|
|
|
|
|
Templating
|
|
|
|
==========
|
2008-03-12 16:37:22 -05:00
|
|
|
|
2008-03-22 08:14:00 -05:00
|
|
|
Sphinx uses the `Jinja <http://jinja.pocoo.org>`_ templating engine for its HTML
|
2008-03-12 16:37:22 -05:00
|
|
|
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.
|
|
|
|
|
2008-03-25 14:20:26 -05:00
|
|
|
|
|
|
|
Do I need to use Sphinx' templates to produce HTML?
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
No. You have several other options:
|
|
|
|
|
2008-04-13 13:16:55 -05:00
|
|
|
* You can write a :class:`~sphinx.application.TemplateBridge` subclass that
|
|
|
|
calls your template engine of choice, and set the :confval:`template_bridge`
|
|
|
|
configuration value accordingly.
|
|
|
|
|
2008-03-25 14:20:26 -05:00
|
|
|
* You can :ref:`write a custom builder <writing-builders>` that derives from
|
|
|
|
:class:`~sphinx.builder.StandaloneHTMLBuilder` and calls your template engine
|
|
|
|
of choice.
|
|
|
|
|
|
|
|
* You can use the :class:`~sphinx.builder.PickleHTMLBuilder` that produces
|
|
|
|
pickle files with the page contents, and postprocess them using a custom tool,
|
|
|
|
or use them in your Web application.
|
|
|
|
|
|
|
|
|
|
|
|
Jinja/Sphinx Templating Primer
|
|
|
|
------------------------------
|
|
|
|
|
2008-03-12 16:37:22 -05:00
|
|
|
The most important concept in Jinja is :dfn:`template inheritance`, which means
|
|
|
|
that you can overwrite only specific blocks within a template, customizing it
|
|
|
|
while also keeping the changes at a minimum.
|
|
|
|
|
2008-03-25 10:22:25 -05:00
|
|
|
Inheritance is done via two (Jinja) directives, ``extends`` and ``block``.
|
2008-03-12 16:37:22 -05:00
|
|
|
|
|
|
|
.. template path
|
|
|
|
blocks
|
|
|
|
extends !template
|
|
|
|
|
2008-04-13 13:16:55 -05:00
|
|
|
template names for other template engines
|
|
|
|
|
|
|
|
.. XXX continue this
|