Metafield filters output the data of a metafield object inside a matching HTML element or as a plain string.

metafield_tag

Creates an HTML element that depends on the metafield type.

{{ product.metafields.instructions.wash | metafield_tag }}

The output differs by metafield type:

singlelinetext_field

single_line_text_field metafields output the text inside a <span> element with the attribute class="metafield-single_line_text_field".

<span class="metafield-single_line_text_field">This is a single line of text.</span>

multilinetext_field

multi_line_text_field metafields output the text inside a <span> element with the attribute class="metafield-multi_line_text_field".

<span class="metafield-multi_line_text_field">This is the first line.<br>This is another line.</span>

page_reference

page_reference metafields output the title of the referenced page inside an <a> element that links to the page and has the attribute class="metafield-page_reference".

<a href="/pages/about-us" class="metafield-page_reference">About us</a>

product_reference

product_reference metafields output the title of the referenced product inside an <a> element that links to the product and has the attribute class="metafield-product_reference".

<a href="/products/the-best-shoes" class="metafield-product_reference">The best shoes</a>

variant_reference

variant_reference metafields output the variant title of the referenced product inside an <a> element that links to the variant and has the attribute class="metafield-variant_reference".

<a href="/products/paper?variant=[variant_id]" class="metafield-variant_reference">A4</a>

file_reference

file_reference metafields output different markup depending on the file type:

  • Image
  • Other

Images in JPEG, PNG and GIF format output an <img> element with these attributes:

Attribute Value
src [image_url] - The image's URL.
alt [image_alt] - The image's alt text.
class metafield-file_reference
<img src="https://cdn.versacommerce.de/[cdn-url-path]/[file-name]" alt="Image alt text" class="metafield-file_reference">

Other files output the preview image of the file inside an <a> element that links to the file and has the attribute class="metafield-file_reference".

<a href="https://cdn.versacommerce.de/[cdn-url-path]/[file-name]" class="metafield-file_reference">
  <img src="https://cdn.versacommerce.de/[cdn-url-path]/[preview-image-name]" loading="lazy">
</a>

number_integer

number_integer metafields output the number inside a <span> element with the attribute class="metafield-number_integer".

<span class="metafield-number_integer">10</span>

number_decimal

number_decimal metafields output the number inside a <span> element with the attribute class="metafield-number_decimal".

<span class="metafield-number_decimal">10.2</span>

date

date metafields output the date in a format localized for the customer inside a <time> element with these attributes:

Attribute Value
datetime [date] - The date.
class metafield-date
<time datetime="2021-05-21" class="metafield-date">May 21, 2021</time>

date_time

date_time metafields output the date and time in a format localized for the customer inside a <time> element with these attributes:

Attribute Value
datetime [date_time] - The date and time.
class metafield-date_time
<time datetime="2021-05-21T18:30:00Z" class="metafield-date_time">May 21, 2021, 6:30pm</time>

url

url metafields output the URL without the protocol inside an <a> element that links to the URL and has the attribute class="metafield-url".

<a href="https://www.example.com" class="metafield-url">www.example.com</a>

json

json metafields output the JSON inside a <script> tag with these attributes:

Attribute Value
type application/json
class metafield-json
<script type="application/json" class="metafield-json">
  {
    "product": "Hand soap",
    "quantity": 22
  }
</script>

boolean

boolean metafields output the value inside a <span> element with the attribute class="metafield-boolean".

<span class="metafield-boolean">true</span>

color

color metafields output the value inside a <span> element with the attribute class="metafield-color".

<span class="metafield-color">#FFFFFF</span>

weight

weight metafields output a <span> element with the attribute class="metafield-weight" that contains one <span> element for each of:

  • the weight value
  • the weight unit
<span class="metafield-weight">
  <span class="metafield-weight_value">3.0</span>
  <span class="metafield-weight_unit">kg</span>
</span>

The weight value is output in a <span> element with the attribute class="metafield-weight_value".

<span class="metafield-weight_value">3.0</span>

The weight unit is output in a <span> element with the attribute class="metafield-weight_unit".

<span class="metafield-weight_unit">kg</span>

volume

volume metafields output a <span> element with the attribute class="metafield-volume" that contains one <span> element for each of:

  • the volume value
  • the volume unit
<span class="metafield-volume">
  <span class="metafield-volume-value">3.0</span>
  <span class="metafield-volume_unit">L</span>
</span>

The volume value is output in a <span> element with the attribute class="metafield-volume-value".

<span class="metafield-volume-value">3.0</span>

The volume unit is output in a <span> element with the attribute class="metafield-volume_unit":

<span class="metafield-volume_unit">L</span>

dimension

dimension metafields output a <span> element with the attribute class="metafield-dimension" that contains one <span> element for each of:

  • the dimension value
  • the dimension unit
<span class="metafield-dimension">
  <span class="metafield-dimension_value">3.0</span>
  <span class="metafield-dimension_unit">m</span>
</span>

The dimension value is output in a <span> element with the attribute class="metafield-dimension_value".

<span class="metafield-dimension_value">3.0</span>

The dimension unit is output in a <span> element with the attribute class="metafield-dimension_unit":

<span aria-hidden="true" class="metafield-dimension_unit">m</span>

rating

rating metafields output the rating value inside a <span> element with the attribute class="metafield-rating":

<span class="metafield-rating">4.8</span>

metafield_text

Creates a text version of the metafield data.

{{ product.metafields.instructions.wash | metafield_text }}

The output for each metafield type:

Metafield Type Output
single_line_text_field The metafield text
multi_line_text_field The metafield text
page_reference The page title
product_reference The product title
variant_reference The variant title
file_reference The file URL
number_integer The number
number_decimal The number
date The date
date_time The date and time
url The URL
json The JSON
boolean The boolean value
color The color value
weight The weight value and unit
volume The volume value and unit
dimension The dimension value and unit
rating The rating value