<p>yes, you could filter the variants for the status <code>enabled</code> to output only the enabled variants of the product.</p>

<pre><code> {% set products = craft.products.all() %}
 {% for product in products %}
     {{ product.title }} &lt;br&gt;
     {% set variants = product.variants|filterByValue('enabled', "1") %}
     {%- for purchasable in variants -%}
          {{ purchasable.id }} - {{ purchasable.description }} - {{ purchasable.price }}&lt;br&gt;
     {%- endfor -%}
 {% endfor %}
</code></pre>

CC BY-SA 4.0
2019-06-25T07:55:42.753Z
2019-06-25T07:55:42.753Z
HendrikEng
<p>To clarify; if I have a disabled variant, and I'm looping through categories (colors) on each product like <code>{% for variantColor in variantColors  %}...{% endfor %}</code> which makes it still show up in the list of colors. </p>

<p>Is there a way to, in that for loop, check if the variant it's connected to is enabled/disabled and then disregard, similar to <code>{% for variant in variants if variant.enabled %}</code>?</p>

CC BY-SA 4.0
2019-06-25T04:09:31.070Z
Just wanted to mention that I solved this within the module I've built to handle product types with categories, but would be great to know how to do this in Twig as opposed to PHP.
Anders
<craft3><plugin-craftcommerce2>
Is there a way to see a fields variant relation in templates?
# Is there a way to see a fields variant relation in templates?

(Asked by: username_0 on 2019-06-25)

To clarify; if I have a disabled variant, and I'm looping through categories (colors) on each product like `{% for variantColor in variantColors %}...{% endfor %}` which makes it still show up in the list of colors.

Is there a way to, in that for loop, check if the variant it's connected to is enabled/disabled and then disregard, similar to `{% for variant in variants if variant.enabled %}`?

**Tags:** craft3, plugin-craftcommerce2
> **Comments:**
> **username_0**: Just wanted to mention that I solved this within the module I've built to handle product types with categories, but would be great to know how to do this in Twig as opposed to PHP.  

---

## 1 answers

### Answer by username_1 on 2019-06-25. Score: 2 | Accepted answer

yes, you could filter the variants for the status enabled to output only the enabled variants of the product.
 {% set products = craft.products.all() %}
 {% for product in products %}
     {{ product.title }} 
     {% set variants = product.variants|filterByValue('enabled', "1") %}
     {%- for purchasable in variants -%}
          {{ purchasable.id }} - {{ purchasable.description }} - {{ purchasable.price }}
     {%- endfor -%}
 {% endfor %}


---

