Document conditional TOC rendering (#1376)

* Document conditional TOC rendering

* Simplify demonstration of conditional rendering
This commit is contained in:
Yngve Høiseth 2021-02-22 21:05:45 +01:00 committed by GitHub
parent 8630c790b8
commit d29693066e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,22 +12,24 @@ documentation for information on its structure.
Here is an example of using that field to render a two-level table of contents: Here is an example of using that field to render a two-level table of contents:
```jinja2 ```jinja2
<ul> {% if page.toc %}
{% for h1 in page.toc %} <ul>
<li> {% for h1 in page.toc %}
<a href="{{h1.permalink | safe}}">{{ h1.title }}</a> <li>
{% if h1.children %} <a href="{{h1.permalink | safe}}">{{ h1.title }}</a>
<ul> {% if h1.children %}
{% for h2 in h1.children %} <ul>
<li> {% for h2 in h1.children %}
<a href="{{h2.permalink | safe}}">{{ h2.title }}</a> <li>
</li> <a href="{{h2.permalink | safe}}">{{ h2.title }}</a>
{% endfor %} </li>
</ul> {% endfor %}
{% endif %} </ul>
</li> {% endif %}
{% endfor %} </li>
</ul> {% endfor %}
</ul>
{% endif %}
``` ```
While headers are neatly ordered in this example, it will work just as well with disjoint headers. While headers are neatly ordered in this example, it will work just as well with disjoint headers.