> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Liquid 中的条件内容

> 使用 if、unless 和 case，以及 Liquid 支持的比较方式，让模板的部分内容只对某些订单打印。

Liquid 可以只在某个条件成立时打印模板的一部分：已付款订单显示“已付款”印章，有礼品留言时显示留言，寄往国外的订单显示海关信息。在可视化编辑器中，请改用区块的 **可见性** 选项卡（请参阅[仅对部分订单显示区块](https://foliant-help.iforiti.com/cn/template-editor/block-conditions.md)）；本文适用于代码模板、**自定义 Liquid** 区块以及区块的 **Liquid 条件** 选项。

## if、elsif 和 else

```liquid theme={null}
{% if financial_status == 'paid' %}
  <p class="stamp">PAID</p>
{% elsif financial_status == 'partially_paid' %}
  <p>Partly paid. {{ 'total_due' | t }}: {{ total_price | minus: total_paid | money }}</p>
{% else %}
  <p>Payment pending</p>
{% endif %}
```

## unless

`unless` 与 `if` 相反：

```liquid theme={null}
{% unless customer.tax_exempt %}
  {% include 'vat_breakdown' %}
{% endunless %}
```

## case

```liquid theme={null}
{% case shipping_address.country_code %}
  {% when 'US', 'CA' %}
    <p>Ships within North America</p>
  {% when 'GB' %}
    <p>Ships within the UK</p>
  {% else %}
    <p>International shipment</p>
{% endcase %}
```

## 比较运算

| 运算符 | 含义 | 示例 |
| - | - | - |
| `==` / `!=` | 等于 / 不等于 | `fulfillment_status == 'fulfilled'` |
| `>` `<` `>=` `<=` | 大于 / 小于 | `total_price >= 10000` |
| `contains` | 文本包含某内容，或列表包含某项 | `tags contains 'Wholesale'` |
| `and` / `or` | 组合多个条件 | `pickup_in_store? or shipping_lines.size == 0` |
| `blank` | 为空或不存在 | `note != blank` |

Liquid 从右向左读取 `and` 和 `or`，并且不支持括号。如果规则较复杂，请嵌套 `if` 标签。

## 常见示例

仅当订单有备注时：

```liquid theme={null}
{% if note != blank %}<p>{{ note | escape }}</p>{% endif %}
```

仅针对金额超过 100.00 的订单（金额以分为单位）：

```liquid theme={null}
{% if total_price >= 10000 %}<p>Free gift included</p>{% endif %}
```

仅针对带有 VIP 标签的客户：

```liquid theme={null}
{% if customer.tags contains 'VIP' %}<p>Thank you for being a VIP!</p>{% endif %}
```

仅针对寄往欧盟以外的订单：

```liquid theme={null}
{% unless shipping_address.member_of_eu %}…customs details…{% endunless %}
```

仅针对草稿订单：

```liquid theme={null}
{% if is_draft_order? %}…{% endif %}
```

## 可视化区块上的 Liquid 条件

区块的 **Liquid 条件** 是放在 `{% if … %}` 内部的那部分：一个表达式，不带标签。例如 `total_price >= 10000 and customer.tags contains 'VIP'`。您输入时，Foliant 会根据示例订单进行检查，并在 Liquid 无法读取时提示您。

## 注意事项

* 文本比较区分大小写：`'vip'` 与 `'VIP'` 不匹配。可视化编辑器中使用 **包含文本** 的标签条件不区分大小写。
* `financial_status` 和 `fulfillment_status` 为小写并使用下划线：`paid`、`partially_refunded`、`unfulfilled`、`partially_fulfilled`。
* 请在预览订单选择器中使用 **示例订单** 和您自己的近期订单来检查条件。请参阅[预览、纸张尺寸和缩放](https://foliant-help.iforiti.com/cn/template-editor/preview-paper-and-zoom.md)。

## 相关文章

* [仅对部分订单显示区块](https://foliant-help.iforiti.com/cn/template-editor/block-conditions.md)
* [订单对象和常用变量](https://foliant-help.iforiti.com/cn/template-editor/liquid-order-variables.md)
* [模板中的金额和货币](https://foliant-help.iforiti.com/cn/template-editor/liquid-money-and-currency.md)
* [编辑模板代码](https://foliant-help.iforiti.com/cn/template-editor/code-editor.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.