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)?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With