简体   繁体   English

如何在Sphinx生成的文档中添加“上一章”和“下一章”链接?

[英]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 . 当我查看文档时,大多数页面底部都有前一章和下一章链接/按钮,例如virtualenv I can't find out how to accomplish this for my project documentation using the Sphinx documentation tool. 我无法使用Sphinx文档工具找到如何为我的项目文档完成此操作。 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: 关于模板的sphinx-doc.org文档提到了nextprev变量:

The next document for the navigation. 导航的下一个文档。 This variable is either false or has two attributes link and title. 此变量为false或具有两个属性link和title。 The title contains HTML markup. 标题包含HTML标记。 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 有关详细信息,请访问: http//www.sphinx-doc.org/en/master/templating.html#next

You can use them anywhere in your Sphinx template and style with CSS accordingly. 您可以在Sphinx模板中的任何位置使用它们,并相应地使用CSS样式。


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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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