# Table of contents with toc shortcode

**URL:** <https://discourse.gohugo.io/t/table-of-contents-with-toc-shortcode/55815>\
**Category:** support\
**Created:** [August 31, 2025, 12:52am UTC](https://discourse.gohugo.io/t/table-of-contents-with-toc-shortcode/55815 "2025-08-31T00:52:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmarkbram](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/robertmarkbram/32/8508_2.png) [@robertmarkbram](https://discourse.gohugo.io/u/robertmarkbram)\
**Post date:** [August 31, 2025, 12:52am UTC](https://discourse.gohugo.io/t/table-of-contents-with-toc-shortcode/55815/1 "2025-08-31T00:52:04Z")

</div>

Hello,

I am having trouble getting a toc working from a custom shortcode. Here is what I have tried.

Versions:

```auto
> hugo version
hugo v0.147.8+extended+withdeploy darwin/arm64 BuildDate=2025-06-07T12:59:52Z VendorInfo=brew
> cat ./go.mod
module example.com

go 1.20

require github.com/McShelby/hugo-theme-relearn v0.0.0-20250603165220-e59b0bd36c54 // indirect
> cat ./themes/hugo-theme-relearn/go.mod
module github.com/McShelby/hugo-theme-relearn

go 1.18

```

My config file `/Users/rob.bram/work/Hugo/Sites/RobPedia/hugo.toml` has toc settings:

```auto
[markup]
  [markup.goldmark]
    [markup.goldmark.extensions]
      definitionList = true
      footnote = true
      linkify = true
      strikethrough = true
      table = true
      taskList = true
      typographer = true
    [markup.goldmark.parser]
      attribute = true
      autoHeadingID = true
      autoHeadingIDType = "github"
    [markup.goldmark.renderer]
      hardWraps = false
      unsafe = true
      xHTML = false
  [markup.tableOfContents]
    endLevel = 5
    ordered = false
    startLevel = 2

```

I create the `toc.html:`

```auto
> cat layouts/shortcodes/toc.html
{{ .Page.TableOfContents }}

```

Then added it to a page:

```auto
---
title: Test page
toc: true
---

**Table of Contents**

{{< toc >}}

```

I refresh the page and see no change it it, but I see this in the console:

```auto
Change detected, rebuilding site (#79).
2025-08-31 10:31:06.687 +1000
Source changed /current-issue/files/runallxsl.md
ERROR Rebuild failed: process: "/Users/rob.bram/ci/files/runAllXsl.md:11:1": failed to extract shortcode: template for shortcode "toc" not found
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 32 ms

```

Any hints would be welcome.

Rob

🙂

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [August 31, 2025, 6:25am UTC](https://discourse.gohugo.io/t/table-of-contents-with-toc-shortcode/55815/2 "2025-08-31T06:25:00Z")

</div>

according to [New template system in Hugo v0.146.0](https://gohugo.io/templates/new-templatesystem-overview/#changes-to-the-layouts-folder) the folder should be named `_shortcodes` (leading underscore)

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 2, 2025, 6:25am UTC](https://discourse.gohugo.io/t/table-of-contents-with-toc-shortcode/55815/3 "2025-09-02T06:25:31Z")

</div>

Closed on September 2, 2025, 6:25am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
