[SOLVED] Select all drafts with 'where'

Following two statements result in zero pages on site with several drafts.
{{ where $.Site.RegularPages ".Draft" "==" "true" }}
{{ where $.Site.RegularPages ".Params.draft" "==" "true" }}

Which is apparently not a bug, since my bug report was closed. I am confused now. How can i get array of all draft pages properly in Hugo?

EDIT: build drafts options is enabled, and drafts can be seen in the output

SOLUTION: {{ where $.Site.RegularPages "Params.draft" true }}

The draft pages are not generated by default.

You need to enable their generation in your project’s config: buildDrafts = "true"

oh, yeah, sorry to not mention it, naturally build drafts is true

Ok. What are you trying to do? Render these pages? If yes. You need to use range with where.

See the Docs: https://gohugo.io/functions/where/#prose

Using where on it own will not get you anywhere.

Also both ".Draft" and ".Params.draft" in your snippet are wrong syntax. It should be "Params.draft"

Indeed, i totally was mistaken about the syntax, but where $.Site.RegularPages "Params.draft" "true" also gives zero pages. It doesn’t matter whether to use range or not, since the array is empty. I tried it both ways.

What i want is to have the number of draft pages on my site, that’s all.

Okay, solved it.

“true” must be without quotes

2 Likes