1
votes

I'm trying to create a section inside the product page where the user chooses a color of a shirt (as well as the size)

I learned that to get separate values for variant options, I should loop through the variants and get variant.option1 for the first option and variant.option2 for the second option.

However, it's rendering each option multiple times since there's a combination (small + red, large + red, hence renders red twice, for example)

How can I render each color once? uniquely?

Also, if anyone could get me a template I could use that renders multiple variants, I'd really appreciate it. Help online is barely available for Shopify.

1

1 Answers

1
votes

Use uniq

{% assign options = '' %}
{% for variant in product.variants %}
    {% assign options = options | append: ',' | append: variant.option2 %}
{% endfor %}
{% assign options = options | remove_first: ',' | split: ',' | uniq %}

{% for option in options %}
{{ option }}<br/>
{% endfor %}