I am using a Rmd file with blogdown to generate a static website. On a particular page I am writing, I would like to add a table of contents toc.
First I tried amending my header yaml like so:
output:
html_document:
toc: true
But after building, no toc were displayed.
I then tried typing just {{.TableOfContents}} into the whitespace of my Rmd file. WHen building and serving, this just rendered {{.TableOfContents}} as text.
I then tried adding it into an html block like so:
{{.TableOfContents}}
This just pasted '{{.TableOfContents}}' in a code highlighted line:
I asked GPT which told me to create a file in layouts/shortcodes and call it toc.html with the content of the shortcode {{.TableOfContents}}, then to refer to {{% toc %}} inside my html block.
This results in the following error when attempting to build:
Total in 47 ms
Error: error building site: failed to render shortcode: "/home/some/path.md:14:1": failed to render shortcode "toc": failed to process shortcode: "/some/path/shortcodes/toc.html:1:3": execute of template failed: template: shortcodes/toc.html:1:3: executing "shortcodes/toc.html" at <.TableOfContents>: can't evaluate field TableOfContents in type *hugolib.ShortcodeWithPage
How can I get a toc to appear in my rendered html page?
