Dynamic sources
Settings for sections and blocks included in a JSON template have the option for merchants to connect one or more dynamic sources to the setting, depending on the setting type.
A dynamic source can be either:
- A metafield value
- A resource attribute
Available values
Anchor link to section titled "Available values"Shopify determines the value of each available dynamic source type based on the following:
- The resource associated with the template that the section is in
- The resource settings in the context of the current setting
For example:
Conditions | Description |
---|---|
The section is included as part of the product template | Metafields and attributes related to the product will be available for the following:
|
The section includes a collection type setting | Metafields and attributes related to the collection will be available for the following:
|
The section's blocks include a product type setting | Metafields and attributes for that product will be available for the block's settings. |
The following table lists the available resources and their associated attributes:
Resource | Attributes |
---|---|
product |
|
collection |
|
page |
|
article |
|
blog |
|
The following outlines which setting and metafield types are compatible:
Setting | Metafield(s) | Metafield validation options |
---|---|---|
collection |
|
|
collection_list |
|
|
color |
|
|
image_picker |
|
|
page |
|
|
product |
|
|
product_list |
|
|
richtext |
|
|
inline_richtext |
|
|
text |
|
|
url |
|
|
video |
|
Must accept video file types |
Referencing metaobject fields
Anchor link to section titled "Referencing metaobject fields"You can use dynamic sources to connect metaobject fields to settings. The metaobject must be referenced in a metaobject_reference
metafield.
When the user selects the metaobject_reference
metafield, they're prompted to select the field that they want to display. Users can select metaobject fields in any settings that support the field's type.
In the case of a list.metaobject_reference
, the metaobject entries attached to the resource are iterated over, and for each metaobject, the selected field's value is displayed in a list.
The values are displayed as a list of the selected field's type. For example, if the selected metaobject field is of type single_line_text_field
, then the values are returned as list.single_line_text_field
.
A merchant has a list.metaobject_reference
metafield that references a Materials metaobject.
Each metaobject has a field called Material name.
You can assign the materials by name to the product in the Metafields section:
In the online store editor, any setting that supports list.single_line_text_field
, such as a rich text field, can use dynamic sources to select the Material name field as a text source:
This outputs a list of the material names associated with the current product:
Default values
Anchor link to section titled "Default values"You can configure a setting's default value to reference a dynamic source. However, only do this if you're rendering a section or block in a context where the dynamic source value exists. For example, don't use a product-related value in a section that:
Can be rendered in non-product templates
Doesn't explicitly have a
product
type setting to provide the necessary value
Additional Liquid is invalid when using this method, so you can only reference the value directly. If you include additional Liquid, then you'll get an error.
The following is an example of a default
setting that references a dynamic source:
Shopify limits the number of dynamic sources that you can use in different areas of your theme. These limits help to keep the theme performant.
Description | Limit |
---|---|
Dynamic sources in a JSON template | 100 |
Dynamic sources in general theme settings | 100 |
Dynamic sources in a section group | 100 |
Dynamic sources in a single setting | 50 |
Dynamic sources in a static section | 50 |