IF AND statement

Hi all, I’m a total newbie to Hugo. I’m trying to display some blog posts on the home page that match 2 criteria:

  1. They are of the blog content type
  2. They have a front matter parameter of “homepage” set to “true”

Here’s what I have so far:

{{ range first 3 (where .Data.Pages "Type" "blog") }}

How can I add an additional AND clause something like:

(where "Params.homepage" "eq" "true")

-------------------------------------- UPDATE ---------------------------------------

I ended up having to modify the query, opening it up to any pages / sections that had the homepage frontmatter field so we could include more than just the blog section so no longer and IF / AND :slight_smile:

For anyone that’s interested here’s what I came up with:

{{ $pages := where .Pages ".Params.homepage" "==" true}}
        {{ range  first 4 $pages }}

Does this help:

Typed this from my phone so no guarantee that it’ll work:

{{ $pages := where .Data.Pages "Type" "blog" }}
{{ $pages := where $pages "Params.homepage" "true" }}
{{ range first 3 $pages }}
...
1 Like

Also see https://gohugo.io/functions/intersect#and-filter-in-where-query

1 Like