pythonpython-sphinxread-the-docsexpandabletoctree

Menu entry in toctree expands/collapses on click and doesn't change page content?


As per the title, is it possible to have a menu entry where the entire entry acts like the +/- for expanding and collapsing and doesn't change the active page?

A bit like when you are already on the actual entry and click it again it only expands/collapses.

index.rst

Introduction
============
Some introductory text here

.. toctree::
   :hidden:

   self
   srg/index

srg/index.rst

srg
===
Normal menu entry that shows this as its page

.. toctree::
   :hidden:

   objects/index

srg/objects/index.rst

Objects
=======
I don't want this to be a page but only an expand/collapse entry.

.. toctree ::
   :hidden:

   list

srg/objects/list.rst

list
====

Page content again

Solution

  • This is totally dependent on the Sphinx theme you use. If one does not support the feature you want out of the box, then you must modify the theme's JavaScript onclick behavior to your desire. Try sphinx_rtd_theme or sphinxbootstrap4theme to get something close or look into its documentation to see if there is a setting that does exactly what you want.