Front Matter Reference
Front matter defines which store resources are available to be rendered within a Stencil template. Front matter is declared at the top of each template and uses YAML syntax. For more information, see Declaring Front Matter Objects.
Supported templates
You can use YAML front matter for templates in the templates/pages/ directory. Injecting objects in the front matter of templates/pages/page.html will make the objects available to custom templates. Also, you can add front matter in the custom folder (i.e., templates/pages/custom).
You cannot use front matter for templates in the following directories:
templates/components/templates/layout/
Global attributes
Global attributes are available on all pages.
Category attributes
Category attributes are available in the context of a category.
Blog attributes
Blog attributes are available in the context of a blog.
Product attributes
Product attributes are available in the context of a product.
Note: The similar_by_views property is not currently active.
Sample GraphQL query for product reviews over the limit.
Brand attributes
Brand list attributes
Search attributes
GraphQL attributes
You can add GraphQL Storefront API queries to your theme using the front matter block in a template file. For example, you can request a product’s variants by augmenting the existing product.html template:
Note: The similar_by_views property is not currently active.
We suggest testing GraphQL Storefront API queries using the playground to refine them before adding them to your template. If your query contains double quotes ", add the escape character to the double-quotes \". You can launch the playground from your store by going to Settings > API > Storefront API Playground in your store control panel.
Once you have added a query to your template’s front matter block, execution happens automatically when the page loads. The data returned by the query will be returned in the page’s context and made available to the handlebars under the gql key. For example, you can retrieve the variant data from the above query in product.html like this:
If the GraphQL query is invalid, Stencil returns an errors object with locations and message properties similar to the following example:
On some pages, you can inject special variables into your query to fetch data relevant to that page. For example, using the $productId variable on product pages injects the product ID associated with the current page.
The following is the complete list of available variables:
category.html:$categoryIdproduct.html:$productIdbrand.html:$brandIdpage.html:$pageIdcontact-us.html:$pageIdblog-post.html:$blogPostId
You can also query data without using variables. The following query returns the product category tree as a JSON object:
The example query returns the following JSON object: