简体   繁体   English

在条件语句中分配 shopify 液体变量

[英]Assign shopify liquid variables inside conditional statements

I've written the following code我写了以下代码

        {% case NAME %}
         {% when "abc" %}
          {% assign varOne = "123" %}
          {% assign varTwo = "345" %}
         {% when "bac" %}
          {% assign varOne = "321" %}
          {% assign varTwo = "543" %}
        {% endcase %}
        
       <p>{{ varOne }}</p>
       <p>{{ varTwo }}</p>

i wanted to know if shopify allows me to set values like this inside a conditional block in shopify liquid and use them outside the conditional block?我想知道 shopify 是否允许我在 shopify 液体的条件块内设置这样的值并在条件块外使用它们? are there any scope related implications for the same?是否有任何与 scope 相关的含义?

Shopify allow to use {% assign %} method inside conditional {% case %} statements. Shopify 允许在条件 {% case %} 语句中使用 {% assign %} 方法。

{% assign food = 'cake' %}

{% case food %}
{% when 'cake' %}
    {% assign isTasty = 'true' %}
{% when 'carrot' %}
    {% assign isTasty = 'false' %}
{% endcase %}

{{ isTasty }}

This will return 'true'这将返回“真”

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

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