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.

1 Answer 1

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

6
  • 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 <pythondir>\Lib\site-packages\Sphinx-1.1.3-py2.7.egg\sphinx\themes\<themename>\layout.html
    – Boinst
    Commented Dec 30, 2012 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 <div class="footer"> tag.
    – Dennis
    Commented Jan 11, 2013 at 0: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! Commented Sep 12, 2014 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. Commented Nov 24, 2016 at 5:34
  • 9
    For RTD theme: {% extends '!footer.html' %} {% block extrafooter %} <!-- your html code here --> {% endblock %} Commented Nov 24, 2016 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.