hugo/content/en/methods/page/TableOfContents.md
Bjørn Erik Pedersen 9b0050e9aa Squashed 'docs/' content from commit 5c085a37b
git-subtree-dir: docs
git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2024-01-27 10:48:33 +01:00

1.1 KiB

title description categories keywords action
TableOfContents Returns a table of contents for the given page.
related returnType signatures
methods/page/Fragments
template.HTML
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.

This template code:

{{ .TableOfContents }}

Produces this 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 >}}