控制流標(biāo)記(control flow tag)能夠根據(jù)編程邏輯改變 Liquid 輸出的信息。
只有當(dāng)某個條件為?true?時才執(zhí)行一段代碼。
true
輸入
{% if product.title == 'Awesome Shoes' %} These shoes are awesome! {% endif %}
輸出
These shoes are awesome!
與?if?相對 – 只有當(dāng)某個條件不成立時才執(zhí)行一段代碼。
if
{% unless product.title == 'Awesome Shoes' %} These shoes are not awesome. {% endunless %}
These shoes are not awesome.
和如下實(shí)例的執(zhí)行結(jié)果一致:
{% if product.title != 'Awesome Shoes' %} These shoes are not awesome. {% endif %}
為?if?或?unless?添加更多狀態(tài)判斷。
unless
<!-- If customer.name = 'anonymous' --> {% if customer.name == 'kevin' %} Hey Kevin! {% elsif customer.name == 'anonymous' %} Hey Anonymous! {% else %} Hi Stranger! {% endif %}
Hey Anonymous!
創(chuàng)建一個開關(guān)表達(dá)式,用于將一個變量和多個不同值進(jìn)行比較。case?用于初始化一個開關(guān)表達(dá)式,when?用于比較他們的值。
case
when
{% assign handle = 'cake' %} {% case handle %} {% when 'cake' %} This is a cake {% when 'cookie' %} This is a cookie {% else %} This is not a cake nor a cookie {% endcase %}
This is a cake
? Copyright 2023 深圳藍(lán)曬科技有限公司. 粵ICP備2023054553號-1