Documentation regarding functions#where

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 "" .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.

The documentation assumes that end-users understand the difference between variables and values.

OK, that makes sense. I have a follow up question:

Isn’t a variable? If so, why does that variable get put in quotes but the .Title variable does not?

I’m not a programmer; please bear with me.

Smarter people than me should weigh in, but…

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 "" 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.

1 Like