1. Luke Plant
  2. sphinx


Georg Brandl  committed 8476c23

The ``toctree`` callable in templates now accepts a ``titles_only`` keyword argument.

  • Participants
  • Parent commits 9f62721
  • Branches default

Comments (0)

Files changed (5)


View file
   - Added new theme ``scrolls``, created by Armin Ronacher.
   - #193: Added a ``visitedlinkcolor`` theme option to the default
+  - The ``toctree`` callable in templates now accepts a ``titles_only``
+    keyword argument.
 * Extension API:

File doc/templating.rst

View file
    * ``maxdepth`` (defaults to the max depth selected in the toctree directive):
      the maximum depth of the tree; set it to ``-1`` to allow unlimited depth
+   * ``titles_only`` (false by default): if true, put only toplevel document
+     titles in the tree

File sphinx/builders/html.py

View file
         if self.indexer is not None and title:
             self.indexer.feed(pagename, title, doctree)
-    def _get_local_toctree(self, docname, collapse=True, maxdepth=0):
+    def _get_local_toctree(self, docname, collapse=True, **kwds):
         return self.render_partial(self.env.get_toctree_for(
-            docname, self, collapse))['fragment']
+            docname, self, collapse, **kwds))['fragment']
     def get_outfilename(self, pagename):
         return path.join(self.outdir, os_path(pagename) + self.out_suffix)

File sphinx/environment.py

View file
             node['refuri'] = node['anchorname'] or '#'
         return toc
-    def get_toctree_for(self, docname, builder, collapse, maxdepth=0):
+    def get_toctree_for(self, docname, builder, collapse, **kwds):
         """Return the global TOC nodetree."""
         doctree = self.get_doctree(self.config.master_doc)
         toctrees = []
+        if 'includehidden' not in kwds:
+            kwds['includehidden'] = True
+        if 'maxdepth' not in kwds:
+            kwds['maxdepth'] = 0
+        kwds['collapse'] = collapse
         for toctreenode in doctree.traverse(addnodes.toctree):
             toctree = self.resolve_toctree(docname, builder, toctreenode,
-                                           prune=True, collapse=collapse,
-                                           maxdepth=maxdepth,
-                                           includehidden=True)
+                                           prune=True, **kwds)
         if not toctrees:
             return None

File tests/root/_templates/customsb.html

View file
 {# custom sidebar template #}
 <h4>Custom sidebar</h4>
+{{ toctree(titles_only=True, maxdepth=1) }}