> ## 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 會連同訂單一起載入中繼欄位，但無法載入全部。運作方式如下：

* 您的商店至少需要一個**中繼欄位定義**（在 Shopify 管理介面的「**設定 › 自訂資料**」中）。如果沒有任何定義，就不會載入任何中繼欄位。
* 對於每種類型（訂單、草稿訂單、顧客、產品和子類），Foliant 會依釘選順序載入您**釘選**的定義，每種類型最多 10 個。
* 如果某種類型沒有釘選的定義，Foliant 會載入找到的前 10 個中繼欄位。

因此，若要確保某個中繼欄位會列印出來，請為它建立定義，並在「**設定 › 自訂資料**」中釘選。定義的變更最多可能需要一小時才會反映在文件中。

## 列印中繼欄位

請將 `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 %}
```

## 各類型中繼欄位的列印方式

| 類型 | 列印結果 |
| - | - |
| 文字、網址、日期、顏色… | 以文字呈現的值 |
| 整數、小數 | 可用來比較或計算的數字 |
| 是或否 | `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/zh-Hant/template-editor/liquid-line-items.md)
* [訂單屬性和品項屬性](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-custom-fields.md)
* [訂單物件和常用變數](https://foliant-help.iforiti.com/zh-Hant/template-editor/liquid-order-variables.md)
* [編輯範本的程式碼](https://foliant-help.iforiti.com/zh-Hant/template-editor/code-editor.md)


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