In a shopify template, I create a link with
<a href="{{ featured.url | within: collection }}" class="grid-link-slider">
I need to check if the url contains a certain word "postcard", and if true, set a second class. Unfortunately,
<a href="{{ featured.url | within: collection }}" class="grid-link-slider {% if {{ featured.url | within: collection }} contains "postcard" %}grid-link-postcard{% endif %}">
is not working, "contains" can only be used for strings and also the syntax for sure is invalid. Is there a way to solve this?
I would capture it like so:
{% capture featured_url %}{{ featured.url | within: collection }}{% endcapture %}
<a href="{{ featured_url }}" class="grid-link-slider {% if featured_url contains "postcard" %}grid-link-postcard{% endif %}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With