Publishing to Channel Metafields

This feature is available on the Enterprise plan.

We support publishing up to 1,000 locations to channel metafields. This can be useful if you need to access location data within your stencil theme without making client-side JS requests.

Once this feature is enabled on the Settings page, the channel metafields are republished every time a location is created, updated, or imported.


To enable publishing to metafields, go to Settings and choose Publish to Channel Metafields.

Due to the character limits of metafields, we will store 50 locations per metafield.


The namespace and key of the first metafield is store_locator_by_space_48.locations_page_1 . Further metafields will be published as required, up to a maximum of 20 metafields.


These channel metafields can be requested by adding the following query to the top of your stencil page template:

---
gql: "query channelMetafields {
    channel {
        metafields(namespace:\"store_locator_by_space_48\") {
            edges {
                node {
                    key
                    value
                }
            }
        }
   }
}
"
---

Each metafield contains location data in JSON format. To use, you will first need to parse the metafield value as JSON, and then loop through the items.

{{#each gql.data.site.product.metafields.edges}}
    {{#startsWith 'locations_page_' node.key }}         
        {{#JSONparse node.value}}
            {{#each items}}
                {{{location.name}}}
            {{/each}}
        {{/JSONparse}}
    {{/startsWith}}
{{/each}}

Read more on how to use channel metafields in your stencil theme.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us