A developer is customizing the Dawn theme to display native color swatches on product cards in collection pages without using plugins. The implementation relies on variant metafields (variant.metafields.custom.color) to retrieve hex color codes.
Current Issue:
Color swatches only render correctly on the first product card
Subsequent cards show color names as text but not the actual color swatches
The problem appears related to variable scoping within the product loop
Solutions Attempted:
Multiple users provided revised Liquid code that dynamically detects the ‘Color’ option index using product.options_with_values
Suggestions included renaming the unique_colors variable to seen_colors to avoid scope conflicts
One contributor recommended moving the code to a separate snippet and calling it within the collection loop
Status:
The issue remains unresolved. The proposed code variations have not fixed the rendering problem beyond the first card. One expert suggested this requires advanced customization, potentially involving shop-level metafields or metaobjects to manage color values consistently across all products.
Summarized with AI on October 27.
AI used: claude-sonnet-4-5-20250929.
I’m customizing Dawn and I would like product cards to show color swatches without using a plugin. So far I made it work in a collection page but it only works for the first card, this is the code I’m using:
Hello. Tamela here. To understand your question correctly, do you mean color swatches as in the drop down selection? Normally that is already there automatically. Can you provide a screenshot?
Yes! You’re on the right track with your code. The main issue you’re facing is likely due to how the unique_colors string is being reused or scoped incorrectly in a loop across multiple product cards—this happens in collection pages where multiple product loops occur. Here’s a fixed and improved version that avoids hardcoding color codes and ensures swatches show correctly for each product, not just the first:
You’d only hard code values if your trying to control the sort order because products have variants in an inconsistent order , or have duplication for some reason messing things up in your product architecture making everything more complicated so taking work to fix.
To get around that you need to put some list somewhere of ALL the color values, like a shop level metafield or metaobject, and loop over that to find a current match; and or then also loop over variantsdepending on setup.
As for only working on one product-card move the code to a snippet and call the snippet inside the collections product loop.
And or check for HTML issues cause by your changes to code, etc.
If you need this customization actually working then contact me for services.
Contact info in forum signature below .
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.
The code you posted works like mine except that after the first product card the color names are shown but the colors are not. I’m looking for a different solution, thanks anyway.