if, elsif liquid not working as expected for line item drop down on product page

Highlighted
Shopify Partner
45 3 7

I've recently added in a drop down on certain product pages that adds a line item property to a purchase (in this case it is a pressure amount for a gas strut).

Each type of gas strut has a certain range of pressures it can be pressured to. To restrict what pressures show up for what product I have a series of if/elsif statements (there's only 6 products, 5 range variations).

Originally I was using if/endif statements for each product.handle but the first product seemed to duplicate the dropdown leaving two on that product page. So I've moved to using if/elsif statements as that's probably the more appropriate structure. Now there is no duplicates but it seems that the correct dropdowns aren't being used for the correct product.handles.

Have I misunderstood how if statements work, can they not be chained in this fashion?
Here are the products

https://www.selectlok.com/collections/gas-struts/products/6mm-piston-shaft-gas-strut
https://www.selectlok.com/collections/gas-struts/products/8mm-stainless-steel-piston-shaft-gas-strut
https://www.selectlok.com/collections/gas-struts/products/8mm-piston-shaft-gas-strut
https://www.selectlok.com/collections/gas-struts/products/10mm-piston-shaft-gas-strut
https://www.selectlok.com/collections/gas-struts/products/12mm-piston-shaft-gas-strut
https://www.selectlok.com/collections/gas-struts/products/sp04-series-piston-shaft-gas-strut

And here is the snippet of code

        <div class="product-form__controls-group grid__item medium-up--one-half" style="padding-left:0px;">
          <div class="line-item-property-field product-form__item">
  <label>Pressure</label>
{% if product.handle == '6mm-piston-shaft-gas-strut' %}
  <select required class="required" id="pressure" name="properties[Pressure]">
    <option value="50N">50N</option>
    <option value="100N">100N</option>
    <option value="150N">150N</option>
    <option value="175N">175N</option>
    <option value="200N">200N</option>
    <option value="250N">250N</option>
    <option value="300N">300N</option>
    <option value="350N">350N</option>
    <option value="400N">400N</option>
  </select>
{% elsif product.handle == '8mm-piston-shaft-gas-strut' or '8mm-stainless-steel-piston-shaft-gas-strut' %}
  <select required class="required" id="pressure" name="properties[Pressure]">
    <option value="100N">100N</option>
    <option value="150N">150N</option>
    <option value="175N">175N</option>
    <option value="200N">200N</option>
    <option value="250N">250N</option>
    <option value="300N">300N</option>
    <option value="350N">350N</option>
    <option value="400N">400N</option>
    <option value="450N">450N</option>
    <option value="500N">500N</option>
    <option value="550N">550N</option>
    <option value="600N">600N</option>
    <option value="650N">650N</option>
    <option value="700N">700N</option>
  </select>
{% elsif product.handle == '10mm-piston-shaft-gas-strut' %}
  <select required class="required" id="pressure" name="properties[Pressure]">
    <option value="100N">100N</option>
    <option value="150N">150N</option>
    <option value="175N">175N</option>
    <option value="200N">200N</option>
    <option value="250N">250N</option>
    <option value="300N">300N</option>
    <option value="350N">350N</option>
    <option value="400N">400N</option>
    <option value="450N">450N</option>
    <option value="500N">500N</option>
    <option value="550N">550N</option>
    <option value="600N">600N</option>
    <option value="650N">650N</option>
    <option value="700N">700N</option>
    <option value="750N">750N</option>
    <option value="800N">800N</option>
    <option value="850N">850N</option>
    <option value="900N">900N</option>
    <option value="950N">950N</option>
    <option value="1000N">1000N</option>
    <option value="1050N">1050N</option>
    <option value="1100N">1100N</option>
  </select>
{% elsif product.handle == '12mm-piston-shaft-gas-strut' %}
  <select required class="required" id="pressure" name="properties[Pressure]">
    <option value="100N">100N</option>
    <option value="150N">150N</option>
    <option value="175N">175N</option>
    <option value="200N">200N</option>
    <option value="250N">250N</option>
    <option value="300N">300N</option>
    <option value="350N">350N</option>
    <option value="400N">400N</option>
    <option value="450N">450N</option>
    <option value="500N">500N</option>
    <option value="550N">550N</option>
    <option value="600N">600N</option>
    <option value="650N">650N</option>
    <option value="700N">700N</option>
    <option value="750N">750N</option>
    <option value="800N">800N</option>
    <option value="850N">850N</option>
    <option value="900N">900N</option>
    <option value="950N">950N</option>
    <option value="1000N">1000N</option>
    <option value="1050N">1050N</option>
    <option value="1100N">1100N</option>
    <option value="1150N">1150N</option>
    <option value="1200N">1200N</option>
    <option value="1250N">1250N</option>
    <option value="1300N">1300N</option>
    <option value="1350N">1350N</option>
    <option value="1400N">1400N</option>
    <option value="1450N">1450N</option>
    <option value="1500N">1500N</option>
    <option value="1550N">1550N</option>
    <option value="1600N">1600N</option>
  </select>
{% elsif product.handle == 'sp04-series-piston-shaft-gas-strut' %}
  <select required class="required" id="pressure" name="properties[Pressure]">
    <option value="80N">80N</option>
    <option value="100N">100N</option>
    <option value="150N">150N</option>
    <option value="175N">175N</option>
    <option value="200N">200N</option>
    <option value="250N">250N</option>
    <option value="300N">300N</option>
    <option value="350N">350N</option>
    <option value="400N">400N</option>
    <option value="450N">450N</option>
    <option value="500N">500N</option>
    <option value="550N">550N</option>
    <option value="600N">600N</option>
    <option value="650N">650N</option>
    <option value="700N">700N</option>
    <option value="750N">750N</option>
    <option value="800N">800N</option>
  </select>
{% endif %}
          </div>
</div>

 

0 Likes
Highlighted
Shopify Partner
45 3 7

I guess I was using if/endif and if/elsif improperly!

I switch to using case/when and it seems to be working perfectly!

Hope this helps someone else.....use case/when if there's multiple ifs.

0 Likes