简体   繁体   中英

How can I do an if statement based on option value? [Liquid / Shopify]

How can I run an if statement using liquid in Shopify based on the value of an option in a dropdown?

This is my code for the dropdown that I want to extract the information from:

<div class="grid__item large--one-half"> 
  <label for="ContactFormAddressSame" class="">{{ 'contact.form.addressSame' | t }}</label>
  <select id="ContactFormAddressSame" name="contact[addressSame]">
    <option>Yes</option>
    <option>No</option>
  </select>
</div>

Basically what I want to happen is if the value is equal to 'No' then do something. If 'Yes', don't do anything.

You need to learn the difference between Server side and Client side.

Liquid is server side template language, what you are asking is to execute some Liquid code once a client has updated his select and you can't do this.

Once you see the select in your browser the server side logic was completed and it won't fire again no matter what you do on the client side.

So your best approach is to create two tabs that will handle the two options of the select and based on the selection show the correct tab using JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM