# 运算符

> Liquid 在条件标签中支持的逻辑运算符与比较运算符，包括 contains 的用法，以及运算符从左到右求值的顺序。

## 逻辑运算符与比较运算符

Liquid 支持与 [conditional tags](../tags/conditional) 配合使用的基本逻辑运算符和比较运算符。

| 运算符     | 功能                                    |
| ---------- | --------------------------------------- |
| `==`       | 等于                                    |
| `!=`       | 不等于                                  |
| `>`        | 大于                                    |
| `<`        | 小于                                    |
| `>=`       | 大于或等于                              |
| `<=`       | 小于或等于                              |
| `or`       | 条件 A 或条件 B                         |
| `and`      | 条件 A 且条件 B                         |
| `contains` | 检查字符串中是否包含某字符串或数组元素  |

### contains

您可以使用 `contains` 检查数组或字符串中是否存在某个字符串。不能使用 `contains` 检查对象数组中是否存在某个 object。

```liquid title="代码"
{% if product.tags contains 'hot' %}
  This potion contains hot properties.
{% endif %}
```
```json title="数据"
{
  "product": {
    "tags": [
      "hot"
    ]
  }
}
```

```html title="输出"
This potion contains hot properties.
```

### 运算顺序

在同一个 tag 中使用多个运算符时，运算符从左到右依次求值，且无法更改此顺序。

:::warning
括号 `()` 在 Liquid tags 中不是有效字符。如果尝试使用括号来分组运算符，则该 tag 将不会被渲染。
:::

```liquid title="代码"
{% unless true and false and false or true %}
  This evaluates to true, since Liquid checks tags like this:
	
  ((true and false) and false) or true
  (false and false) or true
  false or true
  true
{% endunless %}
```

```html title="输出"
<!-- empty -->
```
