I’m getting some strange behavior when using dict() in my partial call.
This works as expected, notice the period in the partial call to pass in the current scope
{{ range first 1 (where .Data.Pages “Params.featured” “eq” true) }}
{{ partial “blog/hero” . }}
{{ end }}
This also works fine:
{{ partial “blog/hero” . (dict “abc” “list”) }}
This loses scope: (period after dict)
{{ partial “blog/hero” (dict “abc” “list”) . }}
However in my partial with #2 I get an error can’t evaluate field abc
In my partial with #3 field abc is available but because of loss of scope my partial outputs no content.
The partial call takes two arguments: the partial name, and the context. In #2 and #3 you are passing three args: the partial name, the dot, and the dict.
Pass the dot as part of the dict instead:
{{ partial "foo" ( dict "abc" "list" "dot" . ) }}
The outer “dot” will then be accessible from inside your partial as .dot
So that makes sense, basically passing in scope via a variable.
I didn’t find any mention in the docs that partial calls only accept two parameters. Did I miss that somewhere?
However this solution hasn’t fixed my main issue which is to have the partial output some content, as it’s still lost the scope or is there some way I can set this inside the partial with the new variable?
Is this a case for using Scratch? I’m new to Hugo and haven’t used that yet.