> ## 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/jp/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 %}
```

EU 域外に発送する注文のみ：

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

下書き注文のみ：

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

## ビジュアルブロックの Liquid の条件

ブロックの **Liquidの条件** には、`{% if … %}` の中に入る部分を入力します。タグを含まない、1つの式です。例：`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/jp/template-editor/preview-paper-and-zoom.md)をご覧ください。

## 関連記事

* [特定の注文でのみブロックを表示する](https://foliant-help.iforiti.com/jp/template-editor/block-conditions.md)
* [order オブジェクトとよく使う変数](https://foliant-help.iforiti.com/jp/template-editor/liquid-order-variables.md)
* [テンプレートでの金額と通貨](https://foliant-help.iforiti.com/jp/template-editor/liquid-money-and-currency.md)
* [テンプレートのコードを編集する](https://foliant-help.iforiti.com/jp/template-editor/code-editor.md)


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