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

£可爱£侵袭症+ 提交于 2020-01-01 10:50:30

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/26260726/how-do-i-add-a-previous-chapter-and-next-chapter-link-in-documentation-gener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!