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

## 各类元字段的打印方式

| 类型 | 打印结果 |
| - | - |
| 文本、URL、日期、颜色… | 以文本形式显示的值 |
| 整数、小数 | 可用于比较或计算的数字 |
| 真或假 | `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/cn/template-editor/liquid-line-items.md)
* [订单属性和订单商品属性](https://foliant-help.iforiti.com/cn/template-editor/liquid-custom-fields.md)
* [订单对象和常用变量](https://foliant-help.iforiti.com/cn/template-editor/liquid-order-variables.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.