runhide
#1
I’ve looked through the other questions on here about passing a variable to a partial, but unfortunately they don’t seem to solve my issue.
In layouts/products/single.html, I have the following:
{{$desc := slice}}
{{range (where (where site.RegularPages "Section" "companies") ".Title" "eq" .Params.company)}}
{{$desc = .Description}}
{{end}}
{{partial "products/description.html" (dict "context" . "desc" $desc)}}
In partials/products/description:
{{.desc}}
This results in the error: can't evaluate field desc in type *hugolib.pageState
.
I don’t understand the error. Can someone please explain what I’m doing wrong?
I’m using v0.61.
b_rad
#2
At the top you have $description
but in your range, you are using $desc
. They need to be the same variable name.
runhide
#3
My code is correct, but I accidentally made a typo in my question. I’ve updated my post.
b_rad
#4
What do you get in your single, if you change it to?
{{range (where (where site.RegularPages "Section" "companies") ".Title" "eq" .Params.company)}}
{{.Description}}
{{end}}
runhide
#5
Just managed to figure out what the issue is, I think.
I’m calling the same partial multiple times in single.html.
I’m doing so like in my post:
{{partial "products/description.html" (dict "context" . "desc" $desc)}}
But also later on without passing the variable, like so:
{{partial "products/description.html" .}}
And that’s what’s been causing the issue. An error on my part. Appreciate your help. Thanks.