Using Hugo v0.62.2
We have a page documentation.md
(note, this is a Markdown file) that contains some front matter, content, and refers to a partial code-example.html
.
Inside code-example.html
we have:
<div class="status-{{ .status }}"> ... </div>
We would like to be able to do something like
{{< partial "code-example" (dict "status" "silver") >}}
and have the resulting output be <div class="status-silver"> ... </div>
, or
{{< partial "code-example" (dict "status" "gold") >}}
and get <div class="status-gold"> ... </div>
The error we get is:
unrecognized character in shortcode action: U+0028 '('. Note: Parameters with non-alphanumeric args must be quoted
Seems it doesn’t like the (dict "status" "silver")
part.
First attempt to fix
We created a partial named code-example-silver.html
that references code-example.html
like so.
{{ partial "code-example" (dict "status" "silver") }}
and because of the change of scope, we changed code-example.html
to:
<div class="status-{{ . }}"> ... </div>
And now the output is
<div class="status-map[status:silver]"> ... </div>
if we use
<div class="status-{{ .status }}"> ... </div>
then the error is
<.status>: can't evaluate field status in type *hugolib.ShortcodeWithPage