30

If I have some documentation, like for example Galleria's documentation, how can I set it up so that when I run the make html command it will add a custom footer to each page?

I saw that I could potentially use the LaTeX preamble section of conf.py if I was outputting it to a PDF format.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
cwd
  • 53,018
  • 53
  • 161
  • 198

1 Answers1

38

You have to extend the default layout by providing an html file like this:

{% extends '!layout.html' %}

{% block footer %}
        <!-- your html code here -->
{% endblock %}

Save this in a _templates/ subdirectory as layout.html and make sure to tell conf.py where to find this directory:

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

More information on templating can be found here: https://www.sphinx-doc.org/en/master/development/templating.html#templating

UncleZeiv
  • 18,272
  • 7
  • 49
  • 77
  • 2
    You can also find the layout.html file that you are overriding in your sphinx install directory. Then you can copy out the {% block %} section and override it per UncleZeiv's instructions, changing only the bits you want to change. My file was at \Lib\site-packages\Sphinx-1.1.3-py2.7.egg\sphinx\themes\\layout.html – Boinst Dec 30 '12 at 23:33
  • 7
    In case anyone is wondering, the default location for the `_templates` directory (based on the `templates_path` setting in `conf.py`) is in the same directory that `conf.py` is in, which should be your `source` directory. Also, if you want your footer to have the same styling as the default footer, you will need to surround your footer's HTML in a ` – Dennis Jan 11 '13 at 00:57
  • 1
    Is there a way to change the footer in the generated PDF? I am getting "CONTENTS" there, and while this solution works for the html, it would be nice to know the PDF version, too! – László Papp Sep 12 '14 at 17:35
  • 1
    > If you override a block, call {{ super() }} somewhere to render the block’s content in the extended template – unless you don’t want that content to show up: [docs](http://www.sphinx-doc.org/en/1.4.9/templating.html#jinja-sphinx-templating-primer). – Steven Almeroth Nov 24 '16 at 05:34
  • 8
    For RTD theme: `{% extends '!footer.html' %} {% block extrafooter %} {% endblock %}` – Steven Almeroth Nov 24 '16 at 05:53
  • I needed to add a link which would reference the document itself, so far the {{sourcename}} looks most reliable – Anton Krug Apr 29 '21 at 22:06