Skip to main content

metafield

A metafield attached to a parent object.

To learn about how to access a metafield on a specific object, refer to Access metafields.

PropertiesDescription
valueThe value of the metafield.

The following table outlines the value format for each metafield type:

Type

Returned format

single_line_text_field

multi_line_text_field

A string

product_reference

A product object

collection_reference

A collection object

file_reference

A image object

number_integer

number_decimal

A number

date

date_time

A date string

url

A URL string

json

A JSON object

boolean

A boolean

color

A color string

weight

volume

dimension

A measurement object

rating

A rating object

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, test value, for example {% if product.metafields.custom.spec_text.value != blank %}.