How to expand all the subsections on the sidebar toctree in Sphinx?

Well, i lost approximately 3.4M neurons trying to read sphinx source code (was it written by a bunch of rabbid reckless raccoons ?! so many levels of abstraction).

So :

  • make your own sphinx theme (use a 3rd party theme as a base, very easy. I use ‘readable’ theme for that)
  • in the directory where you have theme.conf, add a “fulltoc.html” template, containing one line:

fulltoc.html:

{{ toctree(collapse=False) }}

(Heh, notice the ‘collapse’ argument?)

  • in sphinx conf.py, modify the html_sidebars option to add your template; and declare your theme

conf.py:

html_theme_path = [customized_readable_theme.get_html_theme_path()]
html_theme="customized_readable"
html_sidebars = {'**': ['fulltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
  • rebuild documentation

Leave a Comment