metafield
Metafields attached to a parent object.
To learn how to access metafields on specific objects, see Metafields.
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.
You cannot create metafields in Handlebars. Metafields can only be created in the following ways:
- In Shopline Admin
- Through Open API
Properties
Returns true if the metafield is of type list, otherwise returns false.
The type of the metafield.
| Possible values |
|---|
| single_line_text_field |
| multi_line_text_field |
| product_reference |
| collection_reference |
| variant_reference |
| page_reference |
| file_reference |
| number_integer |
| number_decimal |
| date |
| date_time |
| url_reference |
| json |
| boolean |
| color |
| weight |
| volume |
| dimension |
| rating |
| list |
| money |
The value of the metafield.
The table below outlines the value formats for each metafield type:
| Type | Return Value |
|---|---|
| String |
| Product Object |
| Collection Object |
| SKU Object |
| Page Object |
| Media Object |
| Number |
| Date |
| URL String |
| JSON Object |
| Boolean |
| Color Object |
| Measurement Object |
| Rating Object |
| List of Values |
| Money Object |
Accessing Metafields
The access path for metafields consists of two layers:
- Namespace - A group of metafields to prevent conflicts.
- Key - The name of the metafield.
With this, you can access metafield objects using the following syntax:
{{ resource.metafields.namespace.key }}
Type: {{ product.metafields.demo_namespace.demo_key.type }}
Value: {{ product.metafields.demo_namespace.demo_key.value }}
Using Variables in Metafield Expressions
{{ assign 'key' 'demo_key' }}
{{ assign 'demoMetafield' (get key product.metafields.demo_namespace) }}
Type: {{ demoMetafield.type }}
Value: {{ demoMetafield.value }}
Accessing json Type Metafields
The value property of json type metafields returns a JSON object.
Weight: {{ product.metafields.info.weight.value.numeric }}
{{#each product.metafields.info.weight.value as |property|}}
{{capitalize @key}}: {{property}}
{{/each}}
Accessing list Type Metafields
The value property of list type metafields returns an array. You can iterate over the array to access the values.
Type: {{ product.metafields.info.multiple.type }}
{{#each product.metafields.info.multiple.value as |item|}}
{{ item.product.title }}
{{/each}}
If the list is of type single_line_text_field, you can also access items in the array by index.
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 }}
Notes for Themes on OS2.0 and Below:
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,
listtype metafields are not supported yet. -
Reference type metafields are not supported yet.
-
The resource object before
metafieldsmust 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 {{!-- 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){{!-- Incorrect --}}
{{ assign 'mf' product.metafields }}
{{ mf.information.pickup_locations.value }}
{{!-- Incorrect --}}
{{ assign 'ns' product.metafields.information }}
{{ ns.pickup_locations.value }}