10

I'm working with Sphinx (sphinx-1.2b1-py2.7). I want a TOC to appear in a sidebar. It seems binary: I can only get both a TOC in the sidebar and a bulleted list in the body of the text, or I get nothing (no TOC in the sidebar and no bulleted list).

When I use the toctree directive like this:

.. toctree::  
   :hidden:

   Topic1  
   Topic2  

Result: no TOC in the sidebar, no bulleted list of topics in body.

When I use the toctree directive like this:

.. toctree::  

   Topic1  
   Topic2  

Result: TOC in the sidebar AND a bulleted list of topics in the body.

I just want the TOC in the sidebar. Other commands (maxdepth, includehidden) don't work. I've seen it done, but cannot get it to work. The conf.py looks fine, but no luck after several days of searching for an answer. Thanks.

4

1 回答 1

5

我也遇到了麻烦;我在这里找到了答案。

TOC 通过调用toctree()inside 来显示,例如,一个名为 layout.html 的文件。特别是,它通过类似于以下的代码片段显示在侧栏中,该代码片段位于<div class="sidebar">

{% block sidebartoc %}
<h3>{{ _('Table Of Contents') }}</h3>
{{ toctree() }}
{% endblock %}

由于我使用的是主题,因此 layout.html 位于目录 _themes 内的主题目录中;否则 layout.html 可能在目录 _templates 中。

在较新版本的 Sphinx 中,:hidden:使用时显示 TOC 需要什么

.. toctree::  
   :hidden:

是将参数添加includehidden=True到对 的调用中toctree(),如

{% block sidebartoc %}
<h3>{{ _('Table Of Contents') }}</h3>
{{ toctree(includehidden=True) }}
{% endblock %}
于 2013-12-30T14:13:13.480 回答