Joerg
April 5, 2018, 12:48pm
1
I want to have a table of contnents on the right sidebar. I put a
shortcode in toc.html
What I do made wrong?
{{ if .Params.toc }}
{{ .TableOfContents }}
{{ end }}
/content/_index.md
---
title: "Handbook"
date: 2018-01-03T18:48:05+01:00
toc: true
draft: false
menu:
main:
name: Handbook
url: /handbook/
weight: 2
---
{{% section class="item-1 outline" %}}
{{% divmd class="item-1 card-nb" %}}
# Handbook
---
{{% /divmd %}}
{{% divmd class="item-8A card-nb" %}}
## General
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula
eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
## Why handbook first
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula
eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
### Advantages
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula
eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient
{{% /divmd %}}
{{% divmd class="item-4D card-toc" %}}
## Table of contents
{{% .TableOfContents %}}
{{% /divmd %}}
{{% /section %}}
regis
April 5, 2018, 2:12pm
2
If this is the code from your shortcode, it should read:
{{ if $.Page.Params.toc }}
{{ $.Page.TableOfContents }}
{{ end }}
Joerg:
{{% .TableOfContents %}}
You call your shortcode using its basename from layouts/shortcode/
It should look more like {{% tableofcontents %}}
Cheers.
Joerg
April 5, 2018, 2:45pm
3
Thank you for your help.
I wrote this lines in shortcode/tableofcontents.html
But nothing happend.
{{ if $.Page.Params.toc }}
{{ $.Page.TableOfContents }}
{{ end }}
this is the code in handbook/_index.md
{{% divmd class="item-4D card-toc" %}}
## Table of contents
{{% tableofcontents %}}
{{% /divmd %}}
{{% /section %}}
regis
April 5, 2018, 3:05pm
4
Do you have a repo somewhere so we can play this this?
regis
April 5, 2018, 6:25pm
6
Hey! I took a look. Turns out any every titles inside your divmd
or your section
shortcodes are ignored by the TOC generator…
You could start researching on that, not sure there is a work around… would be curious to know.
Cheers.
Joerg
April 5, 2018, 6:50pm
7
I tried to find a solution with divmd and without divmd. Nothing works. It seems like I have to create the table of contents by hand. I still have styleguide.md and manuals.md in the directory handbook next to _index.md. How can I display the content as if this content is a single md file?
regis
April 5, 2018, 7:02pm
8
I assure you it works fine if you add a # Title
outside of your shortcodes. I tried it myself. Every titles outside of the shortcodes were included in the TOC.
DirkC
June 19, 2018, 3:34pm
9
I have the same problem as mentioned here: Why TOC is not working?
The table of contents is working fine - as long as the headers are outside a shortcode. Once they are in a short code enclosing the headers the {{ .TableOfContents }} remains empty.
My shortcode basically assigns a class to the paragraph:
htmlclass:
{{ $contentclass := .Get 0 }}
<div class= {{$contentclass}} >
{{ .Inner }}
</div >
In markdown:
{{% htmlclass "content-body-section" %}}
## First H2
Loret Ipsum
{{% / htmlclass %}}
{{% htmlclass "content-body-section" %}}
## Second H2
Loret Ipsum
{{% / htmlclass %}}
## Third H2
In the TOC - only the “Third H2” is listed - the other ones are ignored.
Am I doing something wrong or is this the default behaviour for TOC?
maiki
June 19, 2018, 8:39pm
10
DirkC
June 19, 2018, 9:53pm
11
Ok - Thanks for the update
Is that still the case? I’m getting the same behaviour in Hugo 0.55.x.
zwbetz
Split this topic
June 30, 2019, 2:16pm
13