Skip to main content

metafield_text

metafield | metafield_text
returns string

Generates a text version of the metafield data.


Note

The metafield_text filter doesn't currently support list metafields other than list.single_line_text_field and list.metaobject_reference.


The following outlines the output for each metafield type:

Metafield typeOutput
single_line_text_fieldThe metafield text.
multi_line_text_fieldThe metafield text.
page_referenceThe page title.
product_referenceThe product title.
collection_referenceThe collection title.
variant_referenceThe variant title.
file_referenceThe file URL.
number_integerThe number.
number_decimalThe number.
dateThe date.
date-timeThe date and time.
urlThe URL.
jsonThe JSON.
booleanThe boolean value.
colorThe color value.
weightThe weight value and unit.

If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed.
volumeThe volume value and unit.

If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed.
dimensionThe dimension value and unit.

If the value is a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed.
ratingThe rating value.
list.single_line_text_fieldThe metafield values in sentence format.

For example, if you had the values Toronto, Ottawa, and Vancouver, then the output would be:

Toronto, Ottawa, and Vancouver
moneyThe money value, formatted using the store's HTML with currency setting.
rich_text_fieldThe rich text value as simple text.
{{ product.metafields.information.dosage | metafield_text }}

Output

Potion dosages

The following metafield types produce different output depending on the provided field parameter:

Anchor to list.metaobject_reference

list.metaobject_reference

metafield | metafield_text: field: string

Outputs the list of metaobjects in sentence format. The required field parameter specifies which field should be rendered for each metaobject. The field parameter can reference only metafields of type single_line_text_field.

{{ product.metafields.information.ingredients | metafield_text: field: 'name' }}

Output

Spinach, Kale, and Mushrooms
Anchor to metaobject_reference

metaobject_reference

metafield | metafield_text: field: string

Outputs the metafield text for the metaobject field specified by the required field parameter. The field parameter can reference only metafields of type single_line_text_field.

{{ product.metafields.information.primary_ingredient | metafield_tag: field: 'name' }}

Output

<span class="metafield-single_line_text_field">Spinach</span>
Was this page helpful?