# .TableOfContents in Markdown

**URL:** <https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007>\
**Category:** support\
**Created:** [March 28, 2016, 3:30am UTC](https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007 "2016-03-28T03:30:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![parsiya](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/parsiya/32/1218_2.png) [@parsiya](https://discourse.gohugo.io/u/parsiya)\
**Post date:** [March 28, 2016, 3:30am UTC](https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007/1 "2016-03-28T03:30:41Z")

</div>

Hi all  
I am trying to manually add table of contents to some of my posts. Hugo has a variable named `.TableOfContents` as seen [here](https://gohugo.io/extras/toc/). Obviously I cannot directly use `{{ .TableOfContents }}` in markdown so I created a shortcode.

Let’s call it `toc.html` and it’s pretty simple:

```
{{ .TableOfContents }}

```

We get this error:

```
ERROR: 2016/03/27 error processing shortcode shortcodes/toc.html
ERR: template: shortcodes/toc.html:6:3: executing "shortcodes/toc.html" at <.TableOfContents>: 
TableOfContents is not a field of struct type *hugolib.ShortcodeWithPage

```

Ok, so we switch the template to:

```
{{ .Page.TableOfContents }}

```

No errors but no toc.

From my searches around the forum, it seems like a chicken and egg problem. The toc is generated from BlackFriday, so it is most probably empty before the markdown is completely processed.

I can easily use it in the template by adding `{{ .TableOfContents }}` and it correctly generates a toc. I just take the HTML and manually paste it in the page and remove the code in template and regenerate.

Another thing that comes into my mind is to add a new page parameter to the frontmatter named `toc` and then check it in the template and if it exists create a toc. However, the toc will be added before the `{{ .Content }}` and I want it just right after the `<!--more-->` tag like [this post](http://localhost:1313/blog/2016-03-27-burp-tips-and-tricks-for-non-webapp-testing---part-1-interception-and-proxy-listeners/).

Am I missing something? Is there a much simpler way of doing this or ?

Thanks

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 28, 2016, 8:49am UTC](https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007/2 "2016-03-28T08:49:42Z")

</div>

> [@parsiya](#):
>
> Am I missing something? Is there a much simpler way of doing this or ?

Currently no – but this is in the “wishlist” and I believe I created a Blackfriday issue about “sections support” at some point.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [March 28, 2016, 8:58am UTC](https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007/3 "2016-03-28T08:58:36Z")

</div>

> <https://github.com/russross/blackfriday/issues/166>

---

<div class="post-metadata">

**Author:** ![parsiya](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/parsiya/32/1218_2.png) [@parsiya](https://discourse.gohugo.io/u/parsiya)\
**Post date:** [March 28, 2016, 3:47pm UTC](https://discourse.gohugo.io/t/tableofcontents-in-markdown/3007/4 "2016-03-28T15:47:44Z")

</div>

Thanks @bep. I think I will go with my manual way for now, a little bit of copy/pasting in the end is ok.
