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

# 订单属性和商品项属性

> 打印客户在结账时或商品页面上填写的自定义字段，例如礼品留言、送达日期或刻字内容。

许多商店会向客户收集额外信息：在结账时填写的送达日期或礼品留言（订单属性，也称为购物车属性或备注属性），或在商品页面上填写的刻字内容或姓名缩写（商品项属性）。Shopify 会将这些信息与订单一起保存，您的模板可以将其打印出来。

## 订单属性

`attributes` 包含订单的自定义字段，每个字段都有一个名称和一个值。

打印所有字段：

```liquid theme={null}
{% for attribute in attributes %}
  <p><strong>{{ attribute.first | escape }}:</strong> {{ attribute.last | escape }}</p>
{% endfor %}
```

按名称打印单个字段，名称须与订单中的拼写完全一致：

```liquid theme={null}
{% if attributes['Gift message'] != blank %}
  <p>{{ attributes['Gift message'] | escape }}</p>
{% endif %}
```

## 商品项属性

每个商品项的 `properties` 包含该商品的自定义字段。请在商品项循环中打印它们：

```liquid theme={null}
{% for line_item in line_items %}
  {{ line_item.title }}
  {% for property in line_item.properties %}
    {% unless property.last == blank %}
      <br>{{ property.first | escape }}: {{ property.last | escape }}
    {% endunless %}
  {% endfor %}
{% endfor %}
```

`property.first` 是字段名称，`property.last` 是字段值。

名称以下划线开头的属性（例如 `_bundle_id`）本应保持隐藏。如需将其排除：

```liquid theme={null}
{% assign first_letter = property.first | slice: 0 %}
{% unless first_letter == '_' or property.last == blank %}
  {{ property.first | escape }}: {{ property.last | escape }}
{% endunless %}
```

## 在可视化编辑器中

* **商品表格**：在 **行** 下勾选 **商品项属性（刻字、礼品留言…）**，即可在每个商品的标题下方打印其属性。名称以下划线开头的属性和空属性不会打印。
* 订单属性：使用 **自定义 Liquid** 区块，并填入上面的循环代码。

## 须知

* 请始终为客户输入的内容添加 `| escape`，确保其内容按纯文本打印。
* 订单属性名称区分大小写：`attributes['gift message']` 和 `attributes['Gift message']` 是不同的。
* 存储在元字段而非属性中的数据，打印方式有所不同。请参阅[模板中的元字段](https://foliant-help.iforiti.com/cn/template-editor/metafields.md)。
* 通过 Bold Product Options 或 Infinite Options 做出的选择也属于订单项属性；其付费附加项可以打印在商品下方。请参阅 [商品选项应用（Bold、Infinite Options）](https://foliant-help.iforiti.com/cn/templates/product-options-apps.md)。

## 相关文章

* [模板中的商品项](https://foliant-help.iforiti.com/cn/template-editor/liquid-line-items.md)
* [模板中的元字段](https://foliant-help.iforiti.com/cn/template-editor/metafields.md)
* [Liquid 中的条件内容](https://foliant-help.iforiti.com/cn/template-editor/liquid-conditional-content.md)
* [区块参考](https://foliant-help.iforiti.com/cn/template-editor/block-catalogue.md)


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