---
title: "metafield"

doc_type: static
doc_category: static
doc_version: v20260901
source_url:
  html: 'https://developer.shopline.com/docs/handlebars/objects/metafield'
  md: 'https://developer.shopline.com/docs/handlebars/objects/metafield.md'
---

# metafield

<div class="code-flex">

<div>
  <ObjectSummary>
    Metafields attached to a parent object.
  </ObjectSummary>

<ObjectDescription>
  To learn how to access metafields on specific objects, see Metafields.
</ObjectDescription>

<ObjectDescription>
  Metafields support various data types, which determine the type of information stored in the metafield. You can also use metafield filters to output the content in a type-specific format.
</ObjectDescription>

<ObjectDescription>
  You cannot create metafields in Handlebars. Metafields can only be created in the following ways:
</ObjectDescription>

:::note{title='Note'}
<ul>
  <li>In Shopline Admin</li>
  <li>Through Open API</li>
</ul>
:::

<br />
#### Properties

  <ObjectProperty
    name="list?"
    types={["boolean"]}
  >
    <ObjectSummary>
      Returns `true` if the metafield is of type `list`, otherwise returns `false`.
    </ObjectSummary>
  </ObjectProperty>

  <ObjectProperty
    name="type"
    types={["string"]}
  >
    <ObjectDescription>
      The type of the metafield.
      <table><thead><tr><th>Possible values</th></tr></thead><tbody><tr><td>single_line_text_field</td></tr><tr><td>multi_line_text_field</td></tr><tr><td>product_reference</td></tr><tr><td>collection_reference</td></tr><tr><td>variant_reference</td></tr><tr><td>page_reference</td></tr><tr><td>file_reference</td></tr><tr><td>number_integer</td></tr><tr><td>number_decimal</td></tr><tr><td>date</td></tr><tr><td>date_time</td></tr><tr><td>url_reference</td></tr><tr><td>json</td></tr><tr><td>boolean</td></tr><tr><td>color</td></tr><tr><td>weight</td></tr><tr><td>volume</td></tr><tr><td>dimension</td></tr><tr><td>rating</td></tr><tr><td>list</td></tr><tr><td>money</td></tr></tbody></table>
    </ObjectDescription>
  </ObjectProperty>

  <ObjectProperty name="value">
    <ObjectSummary>
      The value of the metafield.
      <br /> The table below outlines the value formats for each metafield type:
      <table>
        <thead>
            <tr>
                <th>Type</th>
                <th>Return Value</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    `single_line_text_field`<br></br>
                    `multi_line_text_field`
                </td>
                <td>String</td>
            </tr>
            <tr>
                <td>
                    `product_reference`
                </td>
                <td>Product Object</td>
            </tr>
            <tr>
                <td>
                    `collection_reference`
                </td>
                <td>Collection Object</td>
            </tr>
            <tr>
                <td>
                    `variant_reference`
                </td>
                <td>SKU Object</td>
            </tr>
            <tr>
                <td>
                    `page_reference`
                </td>
                <td>Page Object</td>
            </tr>
            <tr>
                <td>
                    `file_reference`
                </td>
                <td>
                    Media Object
                </td>
            </tr>
            <tr>
                <td>
                    `number_integer`<br></br>
                    `number_decimal`
                </td>
                <td>Number</td>
            </tr>
            <tr>
                <td>
                    `date`<br></br>
                    `date_time`
                </td>
                <td>Date</td>
            </tr>
            <tr>
                <td>
                    `url_reference`
                </td>
                <td>URL String</td>
            </tr>
            <tr>
                <td>
                    `json`
                </td>
                <td>JSON Object</td>
            </tr>
            <tr>
                <td>
                    `boolean`
                </td>
                <td>Boolean</td>
            </tr>
            <tr>
                <td>
                    `color`
                </td>
                <td>Color Object</td>
            </tr>
            <tr>
                <td>
                    `weight`<br></br>
                    `volume`<br></br>
                    `dimension`
                </td>
                <td>Measurement Object</td>
            </tr>
            <tr>
                <td>
                    `rating`
                </td>
                <td>Rating Object</td>
            </tr>
            <tr>
                <td>
                    `list`
                </td>
                <td>List of Values</td>
            </tr>
            <tr>
                <td>
                    `money`
                </td>
                <td>Money Object</td>
            </tr>
        </tbody>
    </table>
    </ObjectSummary>

  </ObjectProperty>
</div>

<div>
  <ObjectAccess
    object="metafields"
    global={false}
    parents={[
      {object:"article.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/96arp92pnm7h8rk3#metafields"},
      {object:"blog.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/ysxb57s3p8z99vpc#metafields"},
      {object:"collection.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/bgaerupeyfawz4am#metafields"},
      {object:"customer.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/s3xh1gqr1mjztqdf#metafields"},
      {object:"order.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/p3qwtbcffbycybwg#metafields"},
      {object:"page.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/bcwatgnw6x191p2f#metafields"},
      {object:"product.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/tfzgv1cp3z3wzk1s#metafields"},
      {object:"shop.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/vwapf2hmu9mbjzxp#metafields"},
      {object:"variant.metafields",link:"/docsv2/ec20/hdwvcvrgnfcjf4gq/gjjjhvusthxd5ucy#metafields"},
    ]}
  />
</div>
</div>

<br />
<br />
<div>
  <ObjectDescription>Accessing Metafields</ObjectDescription>
  <ObjectSummary>
    The access path for metafields consists of two layers:
    <ul>
      <li>Namespace - A group of metafields to prevent conflicts.</li>
      <li>Key - The name of the metafield.</li>
    </ul>
    With this, you can access metafield objects using the following syntax:
  </ObjectSummary>
</div>

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

<Example data={['product.metafields.demo_namespace.demo_key']}>
  ```handlebars
  Type: {{ product.metafields.demo_namespace.demo_key.type }}
  Value: {{ product.metafields.demo_namespace.demo_key.value }}
  ```
</Example>

<div>
  <ObjectDescription>Using Variables in Metafield Expressions</ObjectDescription>
</div>

<Example data={['product.metafields.demo_namespace.demo_key']}>
  ```handlebars
  {{ assign 'key' 'demo_key' }}
  {{ assign 'demoMetafield' (get key product.metafields.demo_namespace) }}

  Type: {{ demoMetafield.type }}
  Value: {{ demoMetafield.value }}
  ```
</Example>

<div>
  <ObjectDescription>Accessing `json` Type Metafields</ObjectDescription>
  <ObjectSummary>
    The `value` property of `json` type metafields returns a JSON object.
  </ObjectSummary>
</div>

<Example data={['product.metafields.info.weight']}>
  ```handlebars
  Weight: {{ product.metafields.info.weight.value.numeric }}

  {{#each product.metafields.info.weight.value as |property|}}
    {{capitalize @key}}: {{property}}
  {{/each}}
  ```
</Example>

<div>
  <ObjectDescription>Accessing `list` Type Metafields</ObjectDescription>
  <ObjectSummary>
    The `value` property of `list` type metafields returns an array. You can iterate over the array to access the values.
  </ObjectSummary>
</div>

<Example data={['product.metafields.info.multiple']}>
  ```handlebars
  Type: {{ product.metafields.info.multiple.type }}

  {{#each product.metafields.info.multiple.value as |item|}}
    {{ item.product.title }}
  {{/each}}
  ```
</Example>

<ObjectSummary>
  If the `list` is of type `single_line_text_field`, you can also access items in the array by index.
</ObjectSummary>
  
<Example data={['product.metafields.info.descriptions']}>
  ```handlebars
  Type: {{ product.metafields.info.descriptions.type }}

  First description in list: {{ product.metafields.info.descriptions.value.[0] }}
  Last description in list: {{ last product.metafields.info.descriptions.value }}
  ```
</Example>

<div>
  <ObjectDescription>Notes for Themes on OS2.0 and Below:</ObjectDescription>
  <ObjectSummary>
    Due to implementation differences, there are the following limitations when using metafields on themes of OS2.0 and below:
    - Only support single value type metafields, `list` type metafields are not supported yet.
    - Reference type metafields are not supported yet.
    - The resource object before `metafields` must have a fixed field name and cannot be customized.

        |Resource|Field|
        |--------|-----|
        |Product |product.metafields|
        |Collection |collection.metafields|
        |Variant |variant.metafields|
        |Page |page.metafields|
        |Customer |customer.metafields|
        |Blog |article.metafields|
        |Blog Collection |blog.metafields|
        |Order |order.metafields|
      
      ```handlebars
      {{!-- Correct --}}
      {{ product.metafields.information.pickup_locations.value }}

      {{!-- Incorrect --}}
      {{ assign 'p' product }}
      {{ p.metafields.information.pickup_locations.value }}

      {{!-- Correct --}}
      {{#each collection.products as |product|}}
        {{ product.metafields.information.pickup_locations.value }}
      {{/each}}

      {{!-- Incorrect --}}
      {{#each collection.products as |p|}}
        {{ p.metafields.information.pickup_locations.value }}
      {{/each}}
      ```
    - The format of the value expression must meet `${ownerResource}.metafields.${namespace}.${key}.(value|type)`
      
      ```handlebars
      {{!-- Incorrect --}}
      {{ assign 'mf' product.metafields }}
      {{ mf.information.pickup_locations.value }}

      {{!-- Incorrect --}}
      {{ assign 'ns' product.metafields.information }}
      {{ ns.pickup_locations.value }}
      ```
  </ObjectSummary>
</div>
