> ## 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.

# テンプレートでのメタフィールド

> 注文、下書き注文、顧客、商品、バリエーションのメタフィールドをテンプレートで印刷し、必要なメタフィールドが Foliant に読み込まれるようにします。

メタフィールドは、ストアやアプリが Shopify に保存するカスタムデータです。たとえば、注文のギフトメッセージ、商品の取り扱い表示、顧客のアカウント番号などです。テンプレートでは Liquid を使って印刷できます。コードエディターの **メタフィールド** タブで、種類ごとの書き方を確認できます。

## 始める前に：Foliant が読み込むメタフィールドを確認する

Foliant はメタフィールドを注文と一緒に読み込みますが、すべてを読み込めるわけではありません。仕組みは次のとおりです。

* ストアに **メタフィールドの定義** が 1 つ以上必要です（Shopify 管理画面の **設定 › カスタムデータ**）。定義が 1 つもない場合、メタフィールドは読み込まれません。
* 種類（注文、下書き注文、顧客、商品、バリエーション）ごとに、**ピン留め** した定義を種類ごとに最大 10 件、ピン留めの順に読み込みます。
* ピン留めした定義がない種類では、最初に見つかった 10 件のメタフィールドを読み込みます。

メタフィールドを確実に印刷するには、定義を作成し、**設定 › カスタムデータ** でピン留めしてください。定義の変更が書類に反映されるまで、最大 1 時間かかることがあります。

## メタフィールドを印刷する

`namespace` と `key` を、メタフィールドのネームスペースとキーに置き換えます（例：`custom.gift_message`）。

| メタフィールドの対象 | Liquid |
| - | - |
| 注文または下書き注文 | `{{ order.metafields.namespace.key }}` |
| 顧客 | `{{ customer.metafields.namespace.key }}` |
| 商品 | `{{ line_item.product.metafields.namespace.key }}` |
| バリエーション | `{{ line_item.variant.metafields.namespace.key }}` |

商品とバリエーションのメタフィールドはアイテムごとの値なので、明細のループ内で使用します。

```liquid theme={null}
{% for line_item in line_items %}
  {{ line_item.title }}
  {% if line_item.product.metafields.custom.care_instructions != blank %}
    <br>{{ line_item.product.metafields.custom.care_instructions }}
  {% endif %}
{% endfor %}
```

## メタフィールドのタイプごとの印刷結果

| タイプ | 結果 |
| - | - |
| テキスト、URL、日付、色など | 値がテキストとして表示されます |
| 整数、小数 | 比較や計算に使える数値です |
| true または false | `true` または `false` です。`{% if %}` で使用します |
| リッチテキスト | 書式なしのテキストです |
| 重量、寸法、容量 | `.value` と `.unit` です。例：`{{ … .weight.value }} {{ … .weight.unit }}` |
| 金額 | `.value`（例：`23.00`）と `.unit`（通貨コード）です。セント単位ではありません。 |
| 評価 | `.value`、`.scale_min`、`.scale_max` です |
| JSON、リスト | ループで処理できるリストまたはオブジェクトです |

## 補足

* 空のメタフィールドや存在しないメタフィールドは何も印刷されません。`!= blank` を使うと、そのラベルも非表示にできます。
* ビジュアルテンプレートでは、**カスタム Liquid** ブロックでメタフィールドを印刷します。
* ピッキングリストでは、テンプレートの **ピッキングリスト** 設定で、商品またはバリエーションのメタフィールドを列として表示できます。

## 関連記事

* [テンプレートでの明細](https://foliant-help.iforiti.com/jp/template-editor/liquid-line-items.md)
* [注文属性と明細のプロパティ](https://foliant-help.iforiti.com/jp/template-editor/liquid-custom-fields.md)
* [order オブジェクトとよく使う変数](https://foliant-help.iforiti.com/jp/template-editor/liquid-order-variables.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.