Skip to content

Templates

Templates control what’s rendered on each page in a theme.

Each page type in the storefront should have an associated template type. These can be used to add functionalities and experiences that belong in said pages. For example, you can add upsells in the cart page template.

Location

Templates are located in the templates directory of the theme

└── theme
    ├── layout
    ├── templates
    |   ├── article.json
    |   ├── product.json
    |   ...
    ...

Template types

Each available template type represents a type of page that is available in the seller’s storefront. No types are required, but you must have implemented a type for each page that you want to render, otherwise it will fall back to the defaults.

TODO

List available template types with links to their pages

Schema

A JSON template only accepts a JSON file with a fixed schema and a list of possible attributes or props.

PropertyTypeRequiredDescription
labelstringYesThe template’s name.
wrapperstringNoAn HTML element to wrap the template’s sections.
sectionsobjectYesAn object that uses section identifiers as keys, and section data as the value. A template must contain at least 1 section.
orderarrayNoAn array of section identifiers, listen in the order that they should be rendered. The identifiers must exist as keys in the sections object, and duplicates are not allowed.
layoutstring | nullNoThe filename of the layout into which the template is to be socketed. If omitted, the renderer will default to theme.liquid.

Template wrapper

The wrapper property makes it possible to surround the injected sections with custom HTML tags. The following tags are available: <div>, <main>, and <section>. The format should be a valid CSS selector, that will be converted into a full HTML tag like the following:

json
{
  ...
  "wrapper": "section#section_identifier.section_class[data-attr=attr_value]",
  ...
}
Output
html
<section id="section_identifier" class="section_class" data-attr="attr_value">
    <!-- injected sections -->
</section>

Section data

The sections attribute in a template holds the data for the sections that will be rendered within. Section data cannot be shared across JSON theme templates, so each section must have an identifier that is unique within the template. Templates can render up to 25 sections, and each section can render up to 50 blocks.

Sections can be added to a template in code, or through the Theme Editor. The sections that are able to be socketed may be limited by the templates attribute of the section schema. If no templates attribute is defined, then the section can be socketed into any template.

The following table elaborates on section data format, note that values wrapped in < > are to be provided by the integrator.

json
sections: {
  <section_id>: {
    "type": <section_type>,
    "disabled": <section_disabled>,
    "settings": {
      <setting_id>: <setting_value>
    },
    "blocks": {
      <block_id>: {
        "type": <block_type>,
        "settings": {
          <setting_id>: <setting_value>
        }
      }
    },
    "block_order": <block_order>
  }
}
ValueTypeRequiredDescription
<section_id>stringYesA unique identifier for the section. Alphanumeric characters only.
<section_type>stringYesThe filename for the section to render, minus the extension.
<section_disabled>booleanNoWhen true, the section is not rendered but is still present and customizable. false by default.
<block_id>stringNoA unique identifier for the block. Alphanumeric characters only.
<block_type>stringYesThe type of block to render, as defined in the schema of the section file.
<block_order>string[]NoAn array of block identifiers, ordered as they should be rendered. The identifiers must exist as keys in the blocks object, and duplicates are not allowed.
<setting_id>stringNoThe identifier of the setting as defined in the schema of the section or the block.
<setting_value>mixedYesA valid value for the setting depending on the identifier used.

For example, the following template renders the main-product.liquid and the upsells.liquid sections on the product page, and renders the variants block in the main product section. The filename is templates/product.json:

json
{
    "label": "A product template",
    "sections": {
        "main": {
            "type": "main-product",
            "settings": {
                "show_discount": false
            },
            "blocks": {
                "some_block": {
                    "type": "variants",
                    "settings": {
                        "show_all": false
                    }
                }
            },
            "block_order": ["some_block"]
        },
        "some_other_id": {
            "type": "upsells"
        }
    },
    "order": ["main", "some_other_id"]
}

The following example is the bare minimum template definition:

json
{
    "sections": {
        "some_id": {
            "type": "main_product"
        }
    },
    "order": ["some_id"]
}

index

The index template handles the rendering of the landing page of the store. It is the usually the first page a customer sees, and must therefore provide a large selection of customization options allowing sellers to customize their stores and create unique first impressions and use experiences.

Location

The index template is located in the templates directory of the theme.

└── theme
    ├── layout
    ├── templates
    |   ...
    |   ├── index.json
    |   ...
    ...

product

The product templates handles the rendering of the product page. It is responsible for displaying the product's information, media, and the appropriate forms for variant selection and adding to cart.

Location

The product template is located in the templates directory of the theme.

└── theme
    ├── layout
    ├── templates
    |   ...
    |   ├── product.json
    |   ...
    ...

Content

The product template should include the following:

Variant selector

TODO

Variant selector guide

Quantity input

TODO

Quantity input guide

Checkout inputs

TODO

Checkout inputs guide

Usage

TODO

Alternative options, YouCan JS