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 1.1KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536
  1. +++
  2. title = "Table of Contents"
  3. weight = 60
  4. +++
  5. Each page/section will automatically generate a table of contents for itself based on the headers present.
  6. It is available in the template through the `toc` variable.
  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 contents:
  10. ```jinja2
  11. <ul>
  12. {% for h1 in 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.
  29. Note that all existing HTML tags from the title will NOT be present in the table of contents to
  30. avoid various issues.