Is there a way to do "Where" "Contains"?

Hey guys, I’ve been trying to find a way to display an element if there are no pages containing a string in the URL on the site.

I’ve reached a point where I’m using assign, but when I go to use where with that I find it has to be an exact match. I need to use where and have it match on containing a string eg

{% assign vacancies = site.pages | where: "path", "/current-vacancies/*" %}

but it doesn’t work. I’ve tried it without the slashes and asterisk but that still doesn’t bring back anything useful for me.

Any ideas?

You Can Try

{% if page.path =="/current-vacancies" %}

{% assign vacancies = site.pages %}

{% endif %}

Try where_exp instead:

{% assign vacancies = site.pages | where_exp: "item", "item.path contains 'current-vacancies'" %}
2 Likes

That’s awesome, thanks for helping out!

1 Like