Add "like" comparison operator to the "where" function

Hi there!
I am trying to filter a list to separate it into two different lists.

I am using a (where list key "in" str) as normal and it works, however, I would need something like (where list str "in" key).

What I mean is that my key is a superset of the string I am looking for, so I want to see if the string is in the key, instead of the key in the string. Is there any way to do this in Hugo?

You cannot do this with the where function.

Range through the collection and perform a comparison in each iteration.

Thanks! I was fearing that was the case and I was ranging with an if, but wheres are beautiful! It would be great to be able to do that :slight_smile:

This would be roughly equivalent to the SQL LIKE comparison operator, e.g.,

{{ $regex := `^bar.*$`
{{ where .Pages "" "like" $regex }}

It’s an interesting idea, but I’ll admit I’ve never needed it before.

1 Like