Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I am working on a form where a user will be able to add an existing product into their cart. I have a form and a button users can use and add products to their cart. The product does get added to the cart however, in the case for variants, i want to hide/show if a given product has one. But as it stands now, none of the products have a variant.
```
```
The if/else statement I currently have is not working, it is still displaying the select element on the browser.
I need to display a list of variants if the product has one, but if it doesn't, then the select tag shouldn't be rendered. I have manually added some products and none of them had any variants included to them.
I can add products to the cart through the website im currently working on but i just want to dynamically display or hide the list of variants.
How can i hide/show the select html based on this condition?
Solved! Go to the solution
This is an accepted solution.
I found the solution! Apparently the proper way to write "else if" is not "elseif" but "else if" with a space between. anyway, i hadn't noticed it until today but I had this error on the terminal
"Liquid syntax error (line 27): Unknown tag 'elseif'"
Have you tried outputting the value of "product.variants.size"? The logic looks good, but it is quite odd since it's still outputting the select even though there is no variant at all.
Yes, i have tried doing something similar just to check and see the output, and unless I'm looking at the wrong place, I'm still not seeing anything rendered..
for example I tried this
```
```
And about your suggestion, i tried it like this but still nothing.
```
{% product.variants.size %}
```
Thanks!
btw, this is the rendered html by the browser:
```
<select class="variants-desktop" name="id">
<option value="44439545905283">
Default Title
</option>
</select>
```
This is an accepted solution.
I found the solution! Apparently the proper way to write "else if" is not "elseif" but "else if" with a space between. anyway, i hadn't noticed it until today but I had this error on the terminal
"Liquid syntax error (line 27): Unknown tag 'elseif'"
Good catch! I can't believe it was just a syntax error 🤣
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024