Trying to show articles based on front matter. Here's what I tried, not working

I have the following files in the root of /content
/content/{about,disclaimer,mission,social-contract}.md

Their front matter is:

+++
...
featured = true
...
+++

And in a partial.
{{ range first 3 (where .Site.RegularPages "Params.featured" "true") | shuffle }}

However I am not seeing them displayed on the front end. I also tried .Site.AllPages, but still I’m not seeing anything. What am I doing wrong?

I’m sure this should work. I can’t seem to find any other code that might prevent this from working.

EDIT: The front matter should be featured = "true" apparently. Even boolean values have to be quoted as string in TOML. However, GitHub - toml-lang/toml: Tom's Obvious, Minimal Language says that something = true should be valid. So I’m hoping it’s not a bug in Hugo’s TOML parsing.

No, they don’t.

You need to test for a boolean value in your query:

{{ range first 3 (where .Site.RegularPages "Params.featured" true) | shuffle }}

https://gohugo.io/functions/where/#use-where-with-booleans

2 Likes

Oh I see. I tested for a string value. I see. Makes sense. Thank you again!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.