I am creating a colour swatch selection for my products in Shopify. The swatch only shows if the variant name is equal to 'Colour'. This is fine and working as should.
I am just wondering if there is a better way of assigning the swatch colour rather than manually typing in the hex codes for each colour name.
At the moment I have the following code in my product-template.liquid file.
<label for="ProductSelect-option-{{ option.name }}-{{ value | escape }}" id="swatch-{{ value }}"{% unless variant_label_state %} class="disabled"{% endunless %}/>
So if the colour value is set to Red then the output of the id would be swatch-Red. Now my question is, in CSS the only way I thought of currently is manually typing in:
#swatch-Red { background-color: red; }
but I would have to do this for ALOT of colours. Can anyone think of a more efficient way of doing this? The other thing to keep in mind aswell is I have colours called 'Gunmetal' and 'Pewter'. These are dark and light grey's and obviously those colours are not recognised within CSS.
Any suggestions are appreciated!