The docs regarding where give 3 examples showing that the syntax requires quotes around each value. Example:
{{ range where .Data.Pages "Section" "post" }}
{{ .Content }}
{{ end }}
However, it seems that some values require not using quotes, such as the .Title variable. Example:
{{ range where .Site.Pages "Params.author" .Title }}
{{ .Render "summary" }}
{{ end }}
I spent some time banging my head against the wall thinking that I needed quotes around the .Title variable, so the function wasn’t working. Is this intended behavior? Did I miss this elsewhere in the docs? If it’s intended but not documented, I’d like to update the docs in case others don’t find this obvious.
It’s not clear that it is quotes because you’re passing in the name of the variable/column to use in the comparison. For Title, you’re passing in the value.
That’s a great observation, @sethm. I understand what where is doing, so it never really dawned on me that it might be confusing. I’ll try to explain:
So, the "Params.author" param is the key that we’re going to search on, and .Title is the value we want to match against. The key is a dotted path that where will use as an accessor while it’s traversing .Site.Pages. You need to pass in the key as a quoted string so that the current template doesn’t attempt to evaluate it; the logic inside the where function will handle the evaluation.