# Metafield filters

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

Metafield filters output the data of a [metafield object](https://developer.versacommerce.de/articles/liquid-objects-metafield) inside a matching HTML element or as a plain string.

## metafield_tag

Creates an HTML element that depends on the metafield type.

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

The output differs by metafield type:

## single_line_text_field

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

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

## multi_line_text_field

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

```html
<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"`.

```html
<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"`.

```html
<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"`.

```html
<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` |

```html
<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](https://developer.versacommerce.de/articles/liquid-objects-generic-file#genericfile-previewimage) of the file inside an `<a>` element that links to the file and has the attribute `class="metafield-file_reference"`.

```html
<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"`.

```html
<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"`.

```html
<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` |

```html
<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` |

```html
<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"`.

```html
<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` |

```html
<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"`.

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

## color

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

```html
<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

```html
<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"`.

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

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

```html
<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

```html
<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"`.

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

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

```html
<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

```html
<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"`.

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

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

```html
<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"`:

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

## metafield_text

Creates a text version of the metafield data.

```liquid
{{ 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 |
