简体   繁体   English

如何基于选项值执行if语句? [液体/ Shopify]

[英]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? 如何根据下拉菜单中选项的值在Shopify中使用Liquid运行if语句?

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. Liquid是服务器端模板语言,您要的是一旦客户更新了自己的选择并且无法执行,就执行一些Liquid代码。

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. 因此,最好的方法是创建两个选项卡,这些选项卡将处理选择的两个选项,并根据选择使用JS显示正确的选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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