Mohammad Siavashi
Mohammad Siavashi

Reputation: 1262

Trouble with Hugo Shortcode Variables affecting Table of Contents rendering

Title: Trouble with Hugo Shortcode Variables affecting Table of Contents rendering

I am currently utilizing Hugo (https://gohugo.io/) to serve static documentation, and I've implemented a custom shortcode to incorporate variables within the text. Although I have defined the shortcode and it functions well throughout my .md files with the syntax {{< params "example" >}}, I am encountering an issue specifically related to the Table of Contents (ToC) rendering.

Here's the content of my layouts/shortcodes/params.html:

{{ $variables := getJSON (printf "data/%s-variables.json" .Site.Params.buildFor) }}
{{ $key := .Get 0 }}
{{ $value := index $variables $key }}
{{ $value | safeHTML }}

In the content, using the variable within a heading causes the Table of Contents to display unexpected behavior. For instance:

Within the content, the following header renders correctly:

## Access the {{< params "bookName" >}}

However, the Table of Contents displays the following:

Access the HAHAHUGOSHORTCODE-s1-HBHB

I am seeking guidance on resolving this Table of Contents problem while maintaining the correct rendering of headers within the content. Any assistance or insights would be greatly appreciated.

Upvotes: 0

Views: 238

Answers (1)

Rogelio
Rogelio

Reputation: 1066

Check your shortcode notation, a la: https://discourse.gohugo.io/t/unknown-shortcode-token-error-in-v0-111-x/43387/2

I.e. {{% %}} instead of {{< >}}.

If that doesn't fix, let me know...

Upvotes: 0

Related Questions