How do I get the Table Of Contents into a partial?

Hi,

I can’t figure out how to get the table of contents into a partial. Is it possible?

Thanks, Ryan

{{.TableOfContents}}

If I try that I get…

ERROR: 2017/01/05 09:33:40 template.go:132: template: theme/partials/sidebar.html:9:5: executing "theme/partials/sidebar.html" at <.TableOfContents>: can't evaluate field TableOfContents in type *hugolib.Node in theme/partials/sidebar.html

Moving ToC out of the partial and into the template works as expected.

Using hugo version 0.18.1

It needs to be in a partial in a page and not in a node. The TOC is generated from the heading structure of a markdown content file. I’m guessing you’re using the sidebar.html on a node/list page layout rather than in something like single.html. Can you point me to a repo?

  • Ryan

Thanks, it’s in the baseof.html, which worked if I put the ToC straight in that template, but not a partial referenced from the baseof.html.

Really strange though, I just tried it right this minute, in the sidebar again, and it’s working!

I don’t think I’ve changed anything else, and I updated to the latest version of Hugo before initially posting to make sure I was up to date.

Sorry I’m quite new to Hugo, so still coming to grips with all the concepts. I’m none the wiser though to why it wasn’t working.

Thanks for your help. It makes perfect sense not having the ToC in a node and only from a page. It was the working from the baseof.html template that was throwing me off though.

1 Like

hugolib.Node does not exist in 0.18.*, so you should check your Hugo version (run hugo version)

All I can think is when I updated it before posting I did something stupid and was in the wrong project or the wrong path, or updated the wrong copy of Hugo (I’m running Windows, so manually downloaded, extract, etc).

I can see in the console history, I ran hugo version and it said 0.17. I remember updating it and checking for 0.18.1 and seeing if it fixed the error. But the console doesn’t suggest I did it. Maybe I did it in the wrong project folder, I have no idea, but anyway now it’s definitely 0.18.1.

Hugo Static Site Generator v0.18.1 BuildDate: 2016-12-30T10:03:28+08:00

It’s working fine now.

Thanks again for the help and sorry for posting when it’s just a stupid, probably sleep deprived induced, mistake.

Hey, just glad it worked out.