Searching for string in product.collections

Topic summary

A developer is attempting to check if a product belongs to a collection with a handle containing ‘company’, but the conditional check only works with exact matches like ‘company-1’.

Current Issue:

  • Using product.collections contains 'company-1' works correctly
  • Using product.collections contains 'company' fails to find matches
  • Need partial string matching to accommodate future collections (e.g., ‘company-2’, ‘company-3’)

Code Context:
The developer is working with Liquid templating, mapping collection handles and logging product.collections as JSON to console for debugging.

Status: The question remains unanswered - seeking guidance on proper syntax or method for partial string matching within the collections array.

Summarized with AI on November 23. AI used: claude-sonnet-4-5-20250929.

I’m trying to check if a product is in a collection named ‘company-1’ but it’s only finding it if it’s an exact match. There might be additional collections in the future so I’m trying to search on ‘company’ rather than the exact handle. What am I doing wrong?

{% assign productCollections = product.collections | map: ‘handle’ %}

{% if productCollections contains ‘company’ %} ← Does not find match

//Do something

{% if productCollections contains ‘company-1’ %} ← Match

//Do something