Is there a "starts with" in Shopify Liquid logic?

Bri
Tourist
39 0 1

What I'm wondering is if there's a cleaner way to write the following code:

{% if collection.handle == "adult-wear" or collection.handle == "adult-hoodies" or collection.handle == "adult-zip-hoodies" or collection.handle == "adult-collar-crews" or collection.handle == "adult-jackets" or collection.handle == "adult-pants" or collection.handle == 'adult-multi-colored' %}
<img src="{{ 'bb-adult-wear.jpg' | asset_url }}" alt="What's New" />
{% endif %}
Basically we want a different banner image for the "Adult Wear" category and all of its sub categories.

Mark_Dunkley
Shopify Staff (Retired)
Shopify Staff (Retired)
293 0 11

What about {% collection.handle contains "wear" %}?

0 Likes
ChunkySteveo
New Member
1 0 0

Very late to the party - but if anyone else is looking for a true "Starts with", this was very handy for me - https://github.com/freakdesign/Shopify-code-snippets/blob/master/Starts%20with%20string%20check%20in...

{% assign stringToCheck = 'freakdesign' %}
{% assign startsWith = 'freak' %}
{% assign checkArray = stringToCheck | split:startsWith %}

{% if checkArray[0] == blank %}
  The string {{ stringToCheck }} does start with {{ startsWith }}.
{% else %}
  The string {{ stringToCheck }} does NOT start with {{ startsWith }}.
{% endif %}
0 Likes