<nav class="sidebar-links">
  {% for toc in toctree_data %}
    {% if toc.current %}
    <div class="sidebar-group">
      <p class="caption">
        <span class="caption-text">{{ toc.caption }}</span>
      </p>
      <ul class="{% if toc.current %}current{% endif %}">
        {% for entry in toc.entries %}
          <li class="toctree-l1 {% if entry.current %}current{% endif %}"><a href="{{ pathto(entry.name) }}" class="reference internal {% if entry.current %}current{% endif %}">{{entry.title}}</a>

            {% if entry.children %}
              <ul>
                {% for entry2 in entry.children %}
                  {% if entry.title != entry2.title or entry.children|length > 1 %}
                  <li class="toctree-l2"><a href="{{entry2.href}}" class="reference internal">{{entry2.title}}</a>
                  </li>
                  {% endif %}
                {% endfor %}
              </ul>
            {% endif %}
          </li>

        {% endfor %}
      </ul>
    </div>
    {% endif %}
  {% endfor %}
</nav>
