SirAnn
1
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…
maiki
2
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 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.
SirAnn
3
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?
SirAnn
4
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)
You can achieve that with front matter (toc = true ) and then check for it in a shortcode (if toc = true … else …).