Based on the documentation and this forum topic, using with
should avoid the error. Perhaps the documentation was based on bep’s suggestion, but never tested.
Unless you have any objections, I’ll create a GitHib issue with a minimal failing example.
Side note: in your code you initialize $caption
twice, instead of initializing it (:=
) and then assigning its value (=
). This will not provide the results you expect. For example:
{{- $a := "foo" -}}
{{- $b := "bar" -}}
{{- with $a -}}
{{- $b := "baz" -}}
{{- end -}}
{{ $b }} <!-- prints "bar" not "baz" -->
Do it like this instead:
{{- $a := "foo" -}}
{{- $b := "bar" -}}
{{- with $a -}}
{{- $b = "baz" -}}
{{- end -}}
{{ $b }} <!-- prints "baz" -->