Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include another page’s ToC in Sphinx

I have the following page at plugins/index.html:

Plugin Development
==================

.. toctree::
   :hidden:

   basics/index
   advanced/index


The Basics
----------

- :doc:`basics/gettingstarted`
- :doc:`basics/resources`
- :doc:`basics/i18n`


Advanced Topics
---------------

- :doc:`advanced/models`
- :doc:`advanced/controllers`
- :doc:`advanced/services`

plugin/basics/index.html and plugins/advanced/index.html contain their own toctree’s, which link to the same subpages listed in plugins/index.html. So what I’m wondering is, is there a way to just include those sub toctree’s, rather than manually listing the sub pages out like I’m doing?

I realize that I could just remove the :hidden: flag from the toctree, but the point is I want to keep Basic/Advanced topics in separate lists, with their own headings, intro paragraphs, etc.

like image 243
Brandon Kelly Avatar asked Oct 26 '12 21:10

Brandon Kelly


People also ask

What is Toctree Maxdepth?

toctree:: :maxdepth: 2 intro strings datatypes numeric (many more documents listed here) This accomplishes two things: Tables of contents from all those documents are inserted, with a maximum depth of two, that means one nested heading. toctree directives in those documents are also taken into account.

What is Genindex?

GEN has partnered with American City Business Journals to create the GEN Index, a regional ranking of equity-centered workplaces.

What is Sphinx Toctree?

toctree is a Sphinx-defined directive in which you explicitly list documents whose TOCs will be listed out.

How do you use a sphinx code block?

Literal code blocks (ref) are introduced by ending a paragraph with the special marker :: . The literal block must be indented (and, like all paragraphs, separated from the surrounding ones by blank lines): This is a normal text paragraph.


1 Answers

You can list the entire directory contents like this (or various combinations of these directives):

.. toctree::
  :glob:
  :titlesonly:
  :maxdepth: 2

  **

or I think also like this (untested):

.. toctree::
  :glob:
  :titlesonly:
  :maxdepth: 2

  *
  basics/*
  advanced/*

However, I have found just manually listing things is often the best way to go. While the automatically generated TOCs are nice, they don't allow you much room in terms of formatting (for example, creating sub headings, and changing the order of pages etc).

In our documentation I have done pretty much the same thing you did in the initial question.

like image 52
Adrian Macneil Avatar answered Oct 14 '22 07:10

Adrian Macneil