schema Tag
The schema
tag defines the expected payload for a page or section.
Using schemas to access products and other resources allows templates to be written without specific knowledge of a site’s data.
default and optional
default
can be used to set default props if they aren’t provided in the page JSON. With primitive types they would be a default value, or with resource types they would be default queries like filters
. For list resource types, an empty object can be provided to ensure a default list is loaded.
optional
can be used to not cause the page to render a 404 view. It only applies to a single resource.
Example
{% schema %}
{
"title": {
"type": "string",
"default": "Hello world"
},
"product": {
"type": "item",
"optional": true
},
"products": {
"type": "item-list",
"default": {
"filters": {
"price_min": 10
}
}
},
"locations": {
"type": "location-list",
"default": {}
}
}
{% endschema %}