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