Hey everyone,
I just spent a chunk of time trying to get a shortcode to do what I wanted and I think I’m just missing something.
Let’s say I have a short code that takes a named argument Arg.
{{< my-shortcode arg="testing" >}}
Inside that shortcode I have the following, which works:
{{ define "inner-template" }}
<p>examplevar: {{$.examplevar}}</p>
<p>arrayitem: {{$.arrayitem}}</p>
{{end}}
{{ range .Site.Data.exampleData }}
{{ $dict := (dict "examplevar" $.Params.Arg "arrayitem" .) }}
{{ template "inner-template" $dict }}
{{ end }}
My first version of this, was:
{{ define "inner-template" }}
<p>examplevar: {{$.examplevar}}</p>
<p>arrayitem: {{$.arrayitem}}</p>
{{end}}
{{ range .Site.Data.exampleData }}
{{ template "inner-template" (dict "examplevar" $.Params.Arg "arrayitem" .) }}
{{ end }}
The problem here is that examplevar
isn’t set in the inner-template
block.
I don’t understand how the position of dict can affect the value of examplevar.
Can anyone explain what’s happening?