bdcad38310
* Finishing up site * Make site a bit responsive * Fix menu responsiveness * Remove Fira Sans and revamp a bit text * Update list of syntax and change output of syntax * Add Rust mention * Some doc tweaks * Correct capitalization for GitHub Correct capitalization for GitHub * Some CSS tweaks * More css tweaks + favicon * Add link to my site
34 lines
985 B
Markdown
34 lines
985 B
Markdown
+++
|
|
title = "Table of Contents"
|
|
weight = 60
|
|
+++
|
|
|
|
Each page/section will automatically generate a table of content for itself based on the headers present.
|
|
|
|
It is available in the template through `section.toc` and `page.toc`.
|
|
You can view the [template variables](./documentation/templates/pages-sections.md#table-of-contents)
|
|
documentation for information on its structure.
|
|
|
|
Here is an example of using that field to render a 2-level table of content:
|
|
|
|
```jinja2
|
|
<ul>
|
|
{% for h1 in page.toc %}
|
|
<li>
|
|
<a href="{{h1.permalink | safe}}">{{ h1.title }}</a>
|
|
{% if h1.children %}
|
|
<ul>
|
|
{% for h2 in h1.children %}
|
|
<li>
|
|
<a href="{{h2.permalink | safe}}">{{ h2.title }}</a>
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
{% endif %}
|
|
</li>
|
|
{% endfor %}
|
|
</ul>
|
|
```
|
|
|
|
While headers are neatly ordered in that example, it will work just as well with disjoint headers.
|