操作符

Baklib

发布于:2025-01-02

Liquid 包含了大量逻辑(logical)和比较操作符(comparison operator)。

基本操作符

==

相等

!=

不相等

>

大于

<

小于

>=

大于或等于

<=

小于或等于

or

逻辑或

and

逻辑与

例如:


{% if product.title == "Awesome Shoes" %}
  These shoes are awesome!
{% endif %}

可以在一个标记(tag)中使用多个操作符:


{% if product.type == "Shirt" or product.type == "Shoes" %}
  This is a shirt or a pair of shoes.
{% endif %}

contains(包含)

contains 用于检查在一个字符串中是否存在某个子串。


{% if product.title contains 'Pack' %}
  This product's title contains the word Pack.
{% endif %}

contains 还可以用于检查一个字符串数组中是否存在某个字符串。


{% if product.tags contains 'Hello' %}
  This product has been tagged with 'Hello'.
{% endif %}

contains 只能用于搜索字符串。你不能将其用于从一个对象数组中检查是否存在某个对象。

提交反馈