metafield
A metafield attached to a parent object.
To learn about how to access a metafield on a specific object, refer to Access metafields.
| Properties | Description |
|---|---|
value | The value of the metafield. |
The following table outlines the value format for each metafield type:
Type | Returned format |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Access metafields
The access path for metafields consists of two layers:
namespace- A grouping of metafields to prevent conflicts.key- The metafield name.
Given this, you can access the metafield object with the following syntax:
{{ resource.metafields.namespace.key }}
{{ product.metafields.custom.directions.value }}
Take with a meal
Accessing metafields of type
The value property of metafields of type json returns a JSON object. You can access the properties of this object directly in Liquid, either by name or 0-based index. You can also iterate through the properties.
Temperature: {{ product.metafields.custom.burn_temperature.value.temperature }}
Unit: {{ product.metafields.custom.burn_temperature.value['unit'] }}
{% for property in product.metafields.custom.burn_temperature.value %}
{{ property[0] | capitalize }}: {{ property[1] }}
{% endfor %}
Temperature: 700
Unit: degrees
Temperature: 700
Unit: degrees
Scale: Fahrenheit
Accessing object-type metafields
Some metafield types return an object. Access the nested data through the value property.
A file_reference (image) metafield exposes the file under value. Read the image through value.image, or pass value to the img_url filter:
{{ product.metafields.custom.spec_file.value.image.src }}
{{ product.metafields.custom.spec_file.value | img_url: '200x' }}
A weight, volume, or dimension metafield returns a measurement object:
{{ product.metafields.custom.net_weight.value.value }} {{ product.metafields.custom.net_weight.value.unit }}
20 KILOGRAMS
A rating metafield returns a rating object:
{{ product.metafields.custom.review_score.value.value }} / {{ product.metafields.custom.review_score.value.scale_max }}
4 / 10.0
📘 Tip
Accessing a metafield always returns a metafield object — even when the metafield isn't defined, the result isn't
nil. To check whether a value is present, testvalue, for example{% if product.metafields.custom.spec_text.value != blank %}.