简体   繁体   中英

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)?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM