metafield_text
Generates a plain text string from a metafield object. This filter is suitable for any scenario that does not require HTML tag output, such as titles, text summaries, image alt attributes, and meta descriptions.
{{ metafield | metafield_text() }}
Required params
metafield metafield: The object to be converted into a plain text string.
Optional params
field string: The field name. Required when the metafield type is metaobject_reference or list.metaobject_reference; used to specify the field to output from the metaobject (only single_line_text_field field type is supported).
Examples
Plain text conversion rules vary by metafield type. Below are specific usage examples for different types:
Basic types
| Type | Output text |
|---|---|
boolean | true or false |
single_line_text_field | Single-line raw text |
multi_line_text_field | Multi-line raw text |
rich_text_field | Rich text content with HTML tags removed |
color | Color value |
rating | Rating value |
number_integer | Integer value |
number_decimal | Decimal value |
money | Formatted money value |
date | Formatted date |
date_time | Formatted date and time |
url | URL |
link | Link URL |
json | JSON string |
{{ variable | metafield_text() }}
{{#var mf = product | get_metafields("my_fields") /}}
<!-- boolean -->
{{ mf.is_new_arrival | metafield_text() }}
<!-- single_line_text_field -->
{{ mf.short_description | metafield_text() }}
<!-- multi_line_text_field -->
{{ mf.material_note | metafield_text() }}
<!-- rich_text_field -->
{{ mf.detail_description | metafield_text() }}
<!-- color -->
{{ mf.color_code | metafield_text() }}
<!-- rating -->
{{ mf.customer_rating | metafield_text() }}
<!-- number_integer -->
{{ mf.inventory_limit | metafield_text() }}
<!-- number_decimal -->
{{ mf.fabric_weight | metafield_text() }}
<!-- money -->
{{ mf.member_price | metafield_text() }}
<!-- date -->
{{ mf.release_date | metafield_text() }}
<!-- date_time -->
{{ mf.release_time | metafield_text() }}
<!-- url -->
{{ mf.size_guide_url | metafield_text() }}
<!-- link -->
{{ mf.brand_link | metafield_text() }}
<!-- json -->
{{ mf.spec_json | metafield_text() }}
Complex types
| Type | Output text |
|---|---|
collection_reference | Title of the referenced collection |
page_reference | Title of the referenced page |
product_reference | Title of the referenced product |
variant_reference | Title of the referenced variant |
file_reference | File URL |
{{ variable | metafield_text() }}
{{#var mf = product | get_metafields("my_fields") /}}
<!-- collection_reference -->
{{ mf.related_collection | metafield_text() }}
<!-- page_reference -->
{{ mf.size_guide_page | metafield_text() }}
<!-- product_reference -->
{{ mf.related_product | metafield_text() }}
<!-- variant_reference -->
{{ mf.recommended_variant | metafield_text() }}
<!-- file_reference image -->
{{ mf.product_image | metafield_text() }}
<!-- file_reference video -->
{{ mf.product_video | metafield_text() }}
<!-- file_reference generic_file -->
{{ mf.manual_file | metafield_text() }}
Measurement types
| Type | Output text |
|---|---|
weight | Value and unit |
volume | Value and unit |
dimension | Value and unit |
{{ variable | metafield_text() }}
{{#var mf = product | get_metafields("my_fields") /}}
<!-- weight -->
{{ mf.package_weight | metafield_text() }}
<!-- volume -->
{{ mf.package_volume | metafield_text() }}
<!-- dimension -->
{{ mf.package_width | metafield_text() }}
metaobject_reference
The field specified by field must be of type single_line_text_field.
{{ variable | metafield_text(field="field_name") }}
{{#var mf = product | get_metafields("my_fields") /}}
{{ mf.metaobject | metafield_text(field="color_name") }}
list.metaobject_reference
The field specified by field must be of type single_line_text_field.
List items are automatically joined into a single text string.
{{ variable | metafield_text(field="field_name") }}
{{#var mf = product | get_metafields("my_fields") /}}
{{ mf.metaobjects | metafield_text(field="color_name") }}
list.single_line_text_field
List items are automatically joined into a single text string.
{{ variable | metafield_text() }}
{{#var mf = product | get_metafields("my_fields") /}}
{{ mf.available_colors | metafield_text() }}