# Insert TOC at top of page

**URL:** <https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295>\
**Category:** support\
**Created:** [September 8, 2017, 10:13am UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295 "2017-09-08T10:13:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirAnn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sirann/32/4098_2.png) [@SirAnn](https://discourse.gohugo.io/u/SirAnn)\
**Post date:** [September 8, 2017, 10:13am UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/1 "2017-09-08T10:13:11Z")

</div>

Hi there  
Is it possible to insert a toc of a page at the top of that page (wiki like)?

So far I tried several things:

\layouts\shortcodes\toc.html:

```
 {{ .TableOfContents }}
 {{ .Page.TableOfContents }}
 {{ .Summary }}
 {{ .TableOfContents }}
 {{ .EverythingElse }}

```

and in my content md-file:

```
{{< toc >}}

# Title
## bla1
## bla2

```

but the output show no toc…

---

<div class="post-metadata">

**Author:** ![maiki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/maiki/32/16384_2.png) [@maiki](https://discourse.gohugo.io/u/maiki)\
**Post date:** [September 8, 2017, 11:06am UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/2 "2017-09-08T11:06:26Z")

</div>

Have you put the TOC directly in your template? That may be what you need to do, and you can use the example partial in the [TOC doc](https://gohugo.io/content-management/toc/#template-example-toc-partial) to test it.

If that works, but the shortcode doesn’t, I imagine the shortcode doesn’t have access to the TOC data at render time.

---

<div class="post-metadata">

**Author:** ![SirAnn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sirann/32/4098_2.png) [@SirAnn](https://discourse.gohugo.io/u/SirAnn)\
**Post date:** [September 8, 2017, 11:38am UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/3 "2017-09-08T11:38:55Z")

</div>

I’m pretty new in hugo 😉

For testing reasons I put some stuff into layouts\partials\header.html

## {{ .Title }}

works fine, but

## {{ .TableOfContents }}

is resulting in an emtpy string…

What do I have to do?

---

<div class="post-metadata">

**Author:** ![SirAnn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sirann/32/4098_2.png) [@SirAnn](https://discourse.gohugo.io/u/SirAnn)\
**Post date:** [September 8, 2017, 11:56am UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/4 "2017-09-08T11:56:08Z")

</div>

ok. Finally I got it. Using

```
{{ .Page.TableOfContents }}

```

inside page default html works fine…

But what’s the best way to toggle the toc option inside a md? sometimes I don’t want to see a toc at the top (that’s why tried partials)

---

<div class="post-metadata">

**Author:** ![Leo\_Merkel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/leo_merkel/32/3321_2.png) [@Leo\_Merkel](https://discourse.gohugo.io/u/Leo_Merkel)\
**Post date:** [September 8, 2017, 1:48pm UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/5 "2017-09-08T13:48:44Z")

</div>

You can achieve that with front matter (toc = true ) and then check for it in a shortcode (if toc = true … else …).

---

<div class="post-metadata">

**Author:** ![SirAnn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/sirann/32/4098_2.png) [@SirAnn](https://discourse.gohugo.io/u/SirAnn)\
**Post date:** [September 8, 2017, 2:53pm UTC](https://discourse.gohugo.io/t/insert-toc-at-top-of-page/8295/6 "2017-09-08T14:53:05Z")

</div>

thanks!
