Settings
You can use section JSON schemas to create settings, allowing sellers to customize your theme with little to no technical experience.
These settings can be defined on sections, blocks, or on the theme itself.
Types
There are two main types of settings:
- Input settings - Settings that can hold a value and are configurable by sellers.
- Display settings - These are static values with which you can provide context about parts of your theme to the seller.
Location
Settings can exist in one of two places:
sections/*.liquid- Can be defined on the section's{% schema %}tag. These can either be section settings or block settings, accessible from thesectionandblockobjects respectively.config/settings_schema.json- Can be defined at the theme level. These can be accessed from the globalsettingsobject.
Schema
Settings can be defined as an array of setting schema objects as a settings attribute on the appropriate object.
{
...
"settings": [
{
"type": "header",
"content": "Product settings"
},
{
"id": "product_1",
"type": "text",
"label": "Product identifier",
"info": "Select a product id to display"
}
],
...
}Each setting is checked against its type when the file is saved. The save is rejected when:
typeis not one of the input or display setting types;- an input setting has no
idorlabel, or a display setting has nocontent; - a
rangehas nominormax, or they are not numbers; - a
radioorselecthas nooptionsarray, or avideo_urlhas noacceptarray.
Access
Settings can be accessed by referencing the appropriate liquid object, this can be one of the following:
- The
sectionobject. - The
blockobject. - The global
settingsobject.
For example, if you have your settings as is shown above on each of these liquid object, you may access them as follows:
// settings
Product identifier: {{ settings.product_1 }}
// section
Product identifier: {{ section.settings.product_1 }}
// block
Product identifier: {{ block.settings.product_1 }}Checking for a setting's value
You should always check a setting's value before using it, blank or nil values are converted into an empty string when referenced.
When referencing a simple setting, you may check whether or not it is an empty string by comparing it to the liquid blank object.
{%- if section.settings.product_1 != blank -%}
{{ section.settings.product_1 }}
{%- endif -%}Dynamic sources
You can reference a Liquid object in a section or block setting value with {{ }}. The reference is resolved each time the setting is read in a template. The objects of the page are used.
{
"type": "heading",
"settings": {
"text": "<h2>{{ closest.collection.title }}</h2>"
}
}On a collection page, you get the collection title inside the h2 tag when you print {{ block.settings.text }}.
- In a text setting, such as
text,textareaorrichtext, you can put several references and other text in the value. - In a resource or media setting, such as
product,collectionorimage_picker, use one reference as the whole value, for example{{ closest.product }}. You get the object. - Write a reference as a path to an object, for example
{{ product.title }}or{{ closest.collection.title }}. - Filters and tags are not resolved. A reference with a filter or a tag is printed as text.
- When the object does not exist on the page, the reference is replaced by an empty string.
- References in color settings are not resolved. In color settings, you can use color palette references only.
- You can also use a reference in a schema
defaultor in a preset value.
See the closest object for the nearest product, collection, page, blog or article.
Conditional settings
You can conditionally show or hide a setting in the theme editor based on the current value of another setting in the same section, block, or theme settings category.
Use the visible_if property on any setting to define the condition.
You can conditionally show/hide any input or display setting type.
Note: The referenced
setting_idmust belong to the same settings array as the setting that declaresvisible_if. You cannot reference a setting from a different section, block, or theme settings category.
Structure
visible_if is an object with the following properties:
| Property | Type | Required | Description |
|---|---|---|---|
setting_id | string | Yes | The id of the setting whose value is evaluated. |
value | string | number | boolean | Yes | The value to compare against. |
operator | string | No | The comparison operator. Defaults to ==. |
Operators
| Operator | Description |
|---|---|
== | Equal to (default) |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Examples
Show a setting only when a checkbox is enabled:
{
"type": "checkbox",
"id": "show_overlay",
"label": "Show overlay",
"default": false
},
{
"type": "color",
"id": "overlay_color",
"label": "Overlay color",
"default": "#000000",
"visible_if": {
"setting_id": "show_overlay",
"value": true
}
}Show a setting only when a specific option is selected:
{
"type": "select",
"id": "layout",
"label": "Layout",
"options": [
{ "value": "grid", "label": "Grid" },
{ "value": "list", "label": "List" }
],
"default": "grid"
},
{
"type": "number",
"id": "columns",
"label": "Columns",
"default": 3,
"visible_if": {
"setting_id": "layout",
"value": "grid"
}
}Show a setting based on a numeric threshold:
{
"type": "number",
"id": "item_count",
"label": "Number of items",
"default": 3
},
{
"type": "checkbox",
"id": "show_pagination",
"label": "Show pagination",
"default": false,
"visible_if": {
"setting_id": "item_count",
"operator": ">",
"value": 5
}
}Multiple conditions
To require multiple conditions to all be true simultaneously, pass an array of condition objects. All conditions must be satisfied for the setting to be visible (AND logic).
{
"type": "text",
"id": "button_label",
"label": "Button label",
"visible_if": [
{ "setting_id": "show_button", "value": true },
{ "setting_id": "button_style", "value": "custom" }
]
}Liquid conditions
visible_if can also be a Liquid string:
{
"type": "range",
"id": "logo_height",
"label": "Logo height",
"min": 20,
"max": 120,
"step": 4,
"default": 40,
"visible_if": "{{ settings.logo != blank }}"
}The theme editor evaluates the condition each time a value changes, and shows the setting only when the condition is true. The condition can read:
settings: the theme settings.section.settings: the settings of the section.block.settings: the settings of the block, in a block.
A setting that has no value uses its default. Liquid objects such as product or collection are not available in a condition. If the theme editor cannot evaluate a condition, the setting is shown.
Any other value for visible_if, for example true, is rejected when the theme is saved.