0

I'm trying to test if a product has multiple variants AND/OR test for specific product variants.

{% if product.variants|length > 1 %}

That does not seem to work, even if it is a non-variant product. I understand that even for products without variants there is a 'default' variant, but shouldn't this return false if its a product type without variants given it should have only 1?

1 Answer 1

1

product.variants|length will in fact give you the exact number of variants the product has. If it is giving you an unexpected response, you’re probably just not looking at the right product in the first place. Try outputting the following to create a URL to the product’s edit page in the Control Panel:

<a href="{{ product.getCpEditUrl() }}">{{ product.title }}</a>

Then click on that link from your browser to see the actual product you’re dealing with.

2
  • It goes to the correct product so i don't think that's the issue. Dec 14, 2015 at 14:43
  • Well it's magically working now. I'll create another question for the portion of my question you deleted because that's still not working. Dec 14, 2015 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.