Where statement with or

I’m trying to collect a number of pages that match one of two params.
{{ if or (eq .Params.ml_prediction_gnb 1) (eq .Params.relevant 1) }}

My first try was to use union:

{{ $ml_prediction_gnb := where .Site.RegularPages ".Params.ml_prediction_gnb" 1 }}

{{ $relevant := where .Site.RegularPages ".Params.relevant" 1}}

{{ $oldlisting := union $relevant $ml_prediction_gnb }}

This only shows results when at least $relevant = 1. The value of .Params.relevant can be 0,1 or None.

What would be the best way to get all pages that match one or the other param ?

Assuming that your frontmatter values 0 and 1 are integers (not quoted) instead of strings, what you have posted works correctly.

Try it:

git clone --single-branch -b hugo-forum-topic-35890 https://github.com/jmooring/hugo-testing hugo-forum-topic-35890
cd hugo-forum-topic-35890
hugo server

@jmooring thank you for that, I think I understood the problem.

I was under the assumption that union would keep the order of the listing. When the code is like yours, with .ByDate.Reverse, it outputs what I expected.

Does it make sense?

No. The order of the listing is irrelevant with respect to what is included in the listing.

about what is included, yes. However since I have a lot of items in the listing, I wasn’t seeing the most recent one that matched the query.

This is the link of the production version: Gregory MS
The first article was from December 1st and not December 3rd as it is now.

I understand. So this is resolved?

sure is, thank you again :grin:

1 Like

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