Search code examples
python-sphinxbreadcrumbstableofcontentstoctree

Generate duplicate templates with different breadcrumbs when referenced from different toctrees


My document structure looks like this:

├── common
│   └── shared.rst
├── foo
│   └── foo.rst
├── index.rst
└── zoo
    └── zoo.rst

The generated structure looks like:

├── common
│   └── shared.html (breadcrumbs: home -> zoo -> shared)
├── foo
│   └── foo.html
├── index.html
└── zoo
    └── zoo.html

My toctree for foo & zoo both look like:

.. toctree::
    :includehidden:

    ../common/shared

I want 2 different shared.html files to be compiled one with the breadcrumbs looking like breadcrumbs: home -> zoo -> shared and the other breadcrumbs: home -> foo -> shared. Is this possible with sphinx?

For reference this is my template code for the breadcrumb generation:

<section>
  <ul class="breadcrumbs">
    <li><a href="{{ pathto(master_doc) }}">Home</a></li>
    {% for doc in parents %}
      <li><a href="{{ doc.link|e }}">{{ doc.title }}</a></li>
    {% endfor %}
    {% if title != 'LaunchKey Documentation' %}
      <li><a href="#" class="active">{{ title }}</a></li>
    {% endif %}
  </ul>
</section>

Solution

  • Ended up putting a shared.rst in both /foo and /zoo and used an include to use the shared copy.

    .. include:: ../common/shared.rst