You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

table-of-contents.md 985B

123456789101112131415161718192021222324252627282930313233
  1. +++
  2. title = "Table of Contents"
  3. weight = 60
  4. +++
  5. Each page/section will automatically generate a table of content for itself based on the headers present.
  6. It is available in the template through `section.toc` and `page.toc`.
  7. You can view the [template variables](./documentation/templates/pages-sections.md#table-of-contents)
  8. documentation for information on its structure.
  9. Here is an example of using that field to render a 2-level table of content:
  10. ```jinja2
  11. <ul>
  12. {% for h1 in page.toc %}
  13. <li>
  14. <a href="{{h1.permalink | safe}}">{{ h1.title }}</a>
  15. {% if h1.children %}
  16. <ul>
  17. {% for h2 in h1.children %}
  18. <li>
  19. <a href="{{h2.permalink | safe}}">{{ h2.title }}</a>
  20. </li>
  21. {% endfor %}
  22. </ul>
  23. {% endif %}
  24. </li>
  25. {% endfor %}
  26. </ul>
  27. ```
  28. While headers are neatly ordered in that example, it will work just as well with disjoint headers.