Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a 'previous chapter' and 'next chapter' link in documentation generated by Sphinx?

When I look at documentation, the most pages have a previous chapter and next chapter link/button at the bottom, for example virtualenv. I can't find out how to accomplish this for my project documentation using the Sphinx documentation tool. Could someone tell me how this works or point me to a useful resource (although I already searched a lot)?

like image 449
Appeltabak Avatar asked Oct 08 '14 15:10

Appeltabak


1 Answers

The sphinx-doc.org documentation on templating mentions the next and prev variables:

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 %}

See more at: http://www.sphinx-doc.org/en/master/templating.html#next

You can use them anywhere in your Sphinx template and style with CSS accordingly.


A full example might be:

<ul class="footer_nav">
    {%- if prev %}
      <li class="prev">
        Previous topic: <a href="{{ prev.link|e }}">{{ prev.title }}</a>
      </li>
    {%- endif %}

    {%- if next %}
      <li class="next">
        Next topic: <a href="{{ next.link|e }}">{{ next.title }}</a>
      </li>
    {%- endif %}
</ul>
like image 127
rszalski Avatar answered Sep 26 '22 02:09

rszalski