Debian Codegraph @

docs/content/en/methods/page/TableOfContents.md

raw
1 ---
2 title: TableOfContents
3 description: Returns a table of contents for the given page.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 returnType: template.HTML
9 signatures: [PAGE.TableOfContents]
10 aliases: [/content-management/toc/]
11 ---
12
13 The `TableOfContents` method on a `Page` object returns an ordered or unordered list of the Markdown [ATX][] and [setext][] headings within the page content.
14
15 This template code:
16
17 ```go-html-template
18 {{ .TableOfContents }}
19 ```
20
21 Produces this HTML:
22
23 ```html
24 <nav id="TableOfContents">
25 <ul>
26 <li><a href="#section-1">Section 1</a>
27 <ul>
28 <li><a href="#section-11">Section 1.1</a></li>
29 <li><a href="#section-12">Section 1.2</a></li>
30 </ul>
31 </li>
32 <li><a href="#section-2">Section 2</a></li>
33 </ul>
34 </nav>
35 ```
36
37 By default, the `TableOfContents` method returns an unordered list of level 2 and level 3 headings. You can adjust this in your project configuration:
38
39 {{< code-toggle file=hugo >}}
40 [markup.tableOfContents]
41 endLevel = 3
42 ordered = false
43 startLevel = 2
44 {{< /code-toggle >}}
45
46 [ATX]: https://spec.commonmark.org/current/#atx-headings
47 [setext]: https://spec.commonmark.org/current/#setext-headings