# 类型

每个[元字段](/zh-CN/docs/theme/theme-features/custom-data/metafields/overview)都有一个类型，用于定义其可存储的信息类型。元字段类型具有内置的验证功能和 [Liquid](/zh-CN/docs/theme/references/liquid/objects/metafield) 支持。

## 工作原理

对于元字段定义，该类型将在拥有该元字段定义的资源的每个实例中强制执行。例如，如果您创建了一个名为"shipping"的元字段定义，类型为 `multi_line_text_field`，所有者类型为 `PRODUCT`，则每个商品资源的元字段类型都将是 `multi_line_text_field`。

**Metafield Types**

```json
{
  "product": {
    "metafields": {
      "namespace": "custom",
      "key": "shipping",
      "type": "multi_line_text_field",
      "value": "All health potions are made to order, so it might take up to 2 weeks before your order can be shipped.\n\nThanks for your patience!"
    }
  }
}
```

## 支持的类型

元字段可以使用以下表格中包含的任意类型：

| 类型 | 描述 | 示例值 | 值类型 |
| --- | --- | --- | --- |
| `boolean` | true 或 false 值。 | true | boolean |
| `color` | 颜色的十六进制代码。 | #FFA500 | string |
| `date` | [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) 格式的日期，不预设时区。 | 2030-12-31 | string |
| `date_time` | [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) 格式的日期和时间，不预设时区。 | 2023-07-31 12:20:20 | string |
| `dimension` | 长度数值及单位。有效单位值：`mm`、`cm`、`m`、`in`、`ft`、`yd`。 | {
    "unit": "MILLIMETERS",
    "value": 98.2
} | JSON object |
| `json` | 可序列化为 JSON 的值，可以是对象、数组、字符串、数字、布尔值或 null 值。 | {
    "temperature": 700,
    "unit": "degrees",
    "scale": "Fahrenheit"
} | JSON object |
| `multi_line_text_field` | 多行文本字段。 | All health potions are made to order, so it might take up to 2 weeks before your order can be shipped.

Thanks for your patience! | string |
| `number_decimal` | 带小数点的数字。 | 8.4 | number |
| `number_integer` | 整数。 | 3 | number |
| `rating` | 按指定刻度衡量的评分。 | {
    "scale\_max": "10.0",
    "scale\_min": "0.0",
    "value": 4.5
} | JSON object |
| `single_line_text_field` | 单行文本字段。 | Take with a meal. | string |
| `url` | 使用允许协议的 URL：`https`、`http`。 | https://www.shoplazza.com/ | string |
| `volume` | 体积数值及单位。有效单位值：`ml`、`cl`、`L`、`m3`、`fl oz`、`pt`、`qt`、`gal`、`imp fl oz`、`imp pt`、`imp qt`、`imp gal`。 | {
    "unit": "MILLILITERS",
    "value": 250
} | JSON object |
| `weight` | 重量数值及单位。有效单位值：`kg`、`g`、`lb`、`oz` | {
    "unit": "GRAMS",
    "value": 50
} | JSON object |

## 引用类型

引用类型元字段允许您存储对 Shoplazza 资源的引用。

|
类型

 |

描述

 |

示例值

 |

值类型

 |
| --- | --- | --- | --- |
|

`collection_reference`

 |

对在线商店中某个分类的引用。

 |

[collection object](/zh-CN/docs/theme/references/liquid/objects/collection)

 |

JSON object

 |
|

`file_reference`

 |

对在线商店中某个文件的引用。默认值为 `Image`。

 |

{
"mediaContentType": "IMAGE",
"image": [image object](/zh-CN/docs/theme/references/liquid/objects/image)
}

 |

JSON object

 |
|

`product_reference`

 |

对在线商店中某个商品的引用。

 |

[product object](/zh-CN/docs/theme/references/liquid/objects/product)

 |

JSON object

 |
