All things Shopify and commerce
Hi!
I'm trying to add a unique class to a product card based on tags. I'm 90% of the way there. I updated line 43 of card-product.liquid to have an "if" in the class, looking like this:
<div class="card-wrapper product-card-wrapper underline-links-hover {%- if card_product.tags contains 'non-interactive' -%} non-interactive{%- endif -%}">
My only hangup is that in the final outcome, the last two classes get stuck together like so:
class="card-wrapper product-card-wrapper underline-links-hovernon-interactive"
Any thoughts on how to fix this?
Solved! Go to the solution
This is an accepted solution.
https://shopify.dev/api/liquid/basics/whitespace -- just remove dashes:
{% if card_product.tags contains 'non-interactive' %}
This is an accepted solution.
https://shopify.dev/api/liquid/basics/whitespace -- just remove dashes:
{% if card_product.tags contains 'non-interactive' %}
@blessing2 wrote:add a space before {%- if to prevent the classes from merging
This is wrong -- adding a dash will eat up all whitespace to the closest non-space character.
Thank you @tim !! Worked like a charm. Hoping this will be a good reference for others, too.
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025