Pass Values to Shortcode in Hugo
To pass values to a Hugo shortcode, use
{{ partial "partialFileName" (dict "context" . "myVar" "val") }}
Accessing the variable inside the partial:
{{ .myVar }}
But then everything you would normally reference through the .
changes to use .context
:
{{ .context.Title }}
{{ .context.Scratch.Get "myScratchVar" }}
Source: Stephanie Hobson at https://discourse.gohugo.io/t/how-to-pass-variables-to-a-partial-template/7321/12
It works on my machine in Hugo v0.101.