# Metafield

Metafields store additional information on articles, blogs, collections, customers, orders, pages, products, the shop and variants.

Metafields store additional information on articles, blogs, collections, customers, orders, pages, products, the shop and variants. You [access](#access-metafields) the `metafield` object through the `metafields` attribute of these resources.

Metafields support [several data types](https://developer.versacommerce.de/articles/liquid-basics-types) that define what kind of information the `metafield` object holds. You can also apply [metafield filters](https://developer.versacommerce.de/articles/liquid-filters-metafield-filters) to output metafield data in a standard format.

Metafields of the types `integer`, `json_string` and `string` are older implementations. They do not have the attributes below and do not work with metafield filters. See [Deprecated metafields](#deprecated-metafields).

The `metafield` object has the following attributes:

## metafield.type

Returns the metafield type.

## metafield.value

Returns the value of the metafield.

The value format for each metafield type:

| Type | Returned format |
|---|---|
| `single_line_text_field`<br> `multi_line_text_field` | [A string](https://developer.versacommerce.de/articles/liquid-basics-types#string) |
| `product_reference` | [A product object](https://developer.versacommerce.de/articles/liquid-objects-product) |
| `variant_reference` | [A variant object](https://developer.versacommerce.de/articles/liquid-objects-variant) |
| `page_reference` | [A page object](https://developer.versacommerce.de/articles/liquid-objects-page) |
| `file_reference` | [A generic_file object](https://developer.versacommerce.de/articles/liquid-objects-generic-file)<br> [A media object (images only)](https://developer.versacommerce.de/articles/liquid-objects-media) |
| `number_integer`<br> `number_decimal` | [A number](https://developer.versacommerce.de/articles/liquid-basics-types#number) |
| `date`<br> `date_time` | [A date object](https://developer.versacommerce.de/articles/liquid-objects-date) |
| `url_reference` | [A url string](https://developer.versacommerce.de/articles/liquid-basics-types#string) |
| `json` | [A JSON string](https://developer.versacommerce.de/articles/liquid-basics-types#string) |
| `boolean` | [A boolean](https://developer.versacommerce.de/articles/liquid-basics-types#boolean) |
| `color` | [A color object](https://developer.versacommerce.de/articles/liquid-objects-color) |
| `weight`<br> `volume`<br> `dimension` | [A measurement object](https://developer.versacommerce.de/articles/liquid-objects-measurement) |
| `rating` | [A rating object](https://developer.versacommerce.de/articles/liquid-objects-metafield) |

## Access metafields

The access path for metafields has two levels:

- `namespace` - a group of metafields that avoids conflicts.
- `key` - the name of the metafield.

Access the `metafield` object with this syntax:

```liquid
{{ resource.metafields.namespace.key }}
```

For example, add this metafield to a product:

| Type | Namespace | Key | Data |
|---|---|---|---|
| `single_line_text_field` | `instructions` | `wash` | "Cold" |

With this metafield, the following input creates this output:

```liquid
Type: {{ product.metafields.instructions.wash.type }}
Wash: {{ product.metafields.instructions.wash.value }}
```

```text
Type: single_line_text_field
Wash: Cold
```

## Direct access

Metafields must be accessed directly by their key. For example, you cannot loop over a namespace to get each metafield:

```liquid
{% for field in resource.metafields.namespace %}
  {{ field | metafield_tag }}
{% endfor %}
```

## Deprecated metafields

Deprecated metafields are older metafield types with limited functionality. These metafield types are deprecated:

- `json_string`
- `number`
- `string`

These types do not return the attributes of the metafield object described above. They return the value of the metafield directly.

The returned value type for each deprecated metafield type:

| Metafield type | Returned value type |
|---|---|
| `integer` | [An integer](https://developer.versacommerce.de/articles/liquid-basics-types#number) |
| `json_string` | [A JSON object](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON) |
| `string` | [A string](https://developer.versacommerce.de/articles/liquid-basics-types#string) |

Use a suitable metafield type for new metafields and consider updating deprecated types.

For example, add this metafield to a product:

| Type | Namespace | Key | Data |
|---|---|---|---|
| `string` | `instructions` | `wash` | "Cold" |

With this metafield, the following input creates this output:

```liquid
Wash: {{ product.metafields.instructions.wash }}
```

```text
Wash: Cold
```


## More properties

VersaCommerce also provides these properties on the `metafield` object:

| Properties | Returns |
|---|---|
| `list?` | Whether this metafield represents a list |
