metafield_ tag
Generates an HTML element to host the data from a metafield object.
The type of element that's generated differs depending on the type of metafield.
The filter doesn't currently support list metafields other than and .
Basic types
Most metafield types return a simple HTML element:
| Type | Element | Attributes |
|---|---|---|
boolean | <span> | class="metafield-boolean" |
| <a> | |
color | <span> | class="metafield-color" |
date | <time> | datetime="<the metafield value>"class="metafield-date"Value is localized to the customer |
| <time> | datetime="<the metafield value>"class="metafield-date"Value is localized to the customer |
json | <script> | class="metafield-json" |
money | <span> | class="metafield-money"Value is formatted using the store's HTML with currency setting |
| <span> | |
| <span> | |
| <span> | |
| <a> | |
| <a> | |
rating | <span> | class="metafield-rating" |
| <span> | |
url | <a> | class="metafield-url" |
| <a> | |
| <div> | |
Code
<!-- boolean -->
{{ product.metafields.information.seasonal | metafield_tag }}
<!-- collection_reference -->
{{ product.metafields.information.related_collection | metafield_tag }}
<!-- color -->
{{ product.metafields.details.potion_color | metafield_tag }}
<!-- date -->
{{ product.metafields.information.expiry | metafield_tag }}
<!-- date_time -->
{{ product.metafields.information.brew_date | metafield_tag }}
<!-- json -->
{{ product.metafields.information.burn_temperature | metafield_tag }}
<!-- money -->
{{ product.metafields.details.price_per_ml | metafield_tag }}
<!-- multi_line_text_field -->
{{ product.metafields.information.shipping | metafield_tag }}
<!-- number_decimal -->
{{ product.metafields.information.salinity | metafield_tag }}
<!-- number_integer -->
{{ product.metafields.information.doses_per_day | metafield_tag }}
<!-- page_reference -->
{{ product.metafields.information.dosage | metafield_tag }}
<!-- product_reference -->
{{ product.metafields.information.related_product | metafield_tag }}
<!-- rating -->
{{ product.metafields.details.rating | metafield_tag }}
<!-- single_line_text_field -->
{{ product.metafields.information.directions | metafield_tag }}
<!-- url -->
{{ product.metafields.information.health | metafield_tag }}
<!-- variant_reference -->
{{ product.metafields.information.best_seller | metafield_tag }}
<!-- rich_text_field -->
{{ product.metafields.information.rich_description | metafield_tag }}Data
{
"product": {
"metafields": {}
}
}Output
Complex types
dimension
Outputs a <span> element with the following attribute:
| Attribute | Value |
|---|---|
class | metafield-dimension |
The <span> element contains the following child elements:
| Child element | HTML element | Attributes |
|---|---|---|
| The dimension value. If it's a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. | <span> | |
| The dimension unit. | <span> | |
Code
{{ product.metafields.details.scale_width | metafield_tag }}Data
{
"product": {
"metafields": {}
}
}Output
file_reference
The output varies depending on the type of file. There are the following categories of file type:
| File type | Description |
|---|---|
| Image | Images in the format of jpg, png, gif, heic, and webp. |
| Video | Videos in the format of mov, and mp4. |
| Other | Any other file type. |
Image
Outputs an <img> element with the following attributes:
| Attribute | Value |
|---|---|
src | The image's URL. |
alt | The image's alt text. |
class | |
Video
Outputs a <video> element with the following attributes:
| Attribute | Value |
|---|---|
src | The video's URL. |
poster | The video's preview image (poster) URL. |
playsinline | N/A - Indicates the video will be played "inline" within the element's playback area. |
preload | metadata - Only metadata is pre-fetched before the video is played. |
The <video> element contains the following child elements:
| Child element | HTML element | Attributes |
|---|---|---|
| The video's multimedia playlist source, for HTTP live streaming (HLS) | <source> | |
| The video's original source | <source> | |
| The video's preview (poster) image | <img> | |
Other
Outputs an <a> element with a link to the file and the following attribute:
| Attribute | Value |
|---|---|
class | |
The <a> element contains an <img> element for the file's preview image with the following attributes:
| Attribute | Value |
|---|---|
src | The file's preview image URL. |
loading | lazy - The image isn't loaded until it's almost in view. |
Code
<!-- Image -->
{{ product.metafields.information.promo_image | metafield_tag }}
<!-- Video -->
{{ product.metafields.information.promo_video | metafield_tag }}
<!-- Other -->
{{ product.metafields.information.disclaimers | metafield_tag }}Data
{
"product": {
"metafields": {}
}
}Output
list.metaobject_reference
Outputs a <ul> element by default with the following attribute:
| Attribute | Value |
|---|---|
class | |
The <ul> element contains an <li> element for each metaobject in the list with a class of . The required field parameter specifies which field should be rendered for each metaobject. The field parameter can reference only metafields of type .
To output an <ol> element, pass the parameter with a value of ordered.
Code
<!-- <ul> element -->
{{ product.metafields.information.ingredients | metafield_tag: field: 'name' }}
<!-- <ol> element -->
{{ product.metafields.information.ingredients | metafield_tag: field: 'name', list_format: 'ordered' }}Data
{
"product": {
"metafields": {}
}
}Output
list.single_line_text_field
Outputs a <ul> element by default with the following attribute:
| Attribute | Value |
|---|---|
class | |
The <ul> element contains an <li> element for each item in the list with a class of .
To output an <ol> element, pass the parameter with a value of ordered.
Code
<!-- <ul> element -->
{{ product.metafields.information.pickup_locations | metafield_tag }}
<!-- <ol> element -->
{{ product.metafields.information.pickup_locations | metafield_tag: list_format: 'ordered' }}Data
{
"product": {
"metafields": {}
}
}Output
metaobject_reference
Outputs an HTML element for the metaobject field specified by the required field parameter. The field parameter can reference only metafields of type .
Code
{{ product.metafields.information.primary_ingredient | metafield_tag: field: 'name' }}Data
{
"product": {
"metafields": {}
}
}Output
volume
Outputs a <span> element with the following attribute:
| Attribute | Value |
|---|---|
class | metafield-volume |
The <span> element contains the following child elements:
| Child element | HTML element | Attributes |
|---|---|---|
| The volume value. If it's a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. | <span> | |
| The volume unit. | <span> | |
Code
{{ product.metafields.details.milk_container_volume | metafield_tag }}Data
{
"product": {
"metafields": {}
}
}Output
weight
Outputs a <span> element with the following attribute:
| Attribute | Value |
|---|---|
class | metafield-weight |
The <span> element contains the following child elements:
| Child element | HTML element | Attributes |
|---|---|---|
| The weight value. If it's a decimal with more than two places, then it'll be formatted to have a precision of two with trailing zeros removed. | <span> | |
| The weight unit. | <span> | |
Code
{{ product.metafields.details.chamomile_base_weight | metafield_tag }}Data
{
"product": {
"metafields": {}
}
}