Theme app extension configuration
A theme app extension is a bundle of app blocks, app embed blocks, assets, and snippets.
File structure
Anchor link to section titled "File structure"When you create a theme app extension, Shopify adds the following theme-app-extension
directory and subdirectories to your app:
Subdirectory | Description |
---|---|
assets |
Contains CSS, JavaScript, and other static app content that gets injected into themes. Apps can load assets using either the |
blocks |
Contains app blocks for themes and app embed block Liquid files. |
snippets |
Contains Liquid snippet files for the theme app extension, which are bits of code that you can reference in other app blocks and app embed blocks. |
locales |
Contains JSON locale files to host merchant-facing and customer-facing translations. These files are similar to theme locale files in their schema and usage. You can include the following file types:
Note: Merchants can't edit the strings in theme app extension storefront locale files. |
shopify.extension.toml |
A configuration file containing basic app configuration settings, including the extension name and type ( |
App blocks for themes
Anchor link to section titled "App blocks for themes"Apps that inject inline content on a page extend themes using app blocks. Merchants can add app blocks to a compatible theme section, or as wrapped app blocks that are added at the section level. Create an app block by setting the target
in the schema to section
.
By default, themes don't include app blocks after an app is installed. Merchants need to add the app blocks to the theme from the Apps section of the theme editor.
Use app blocks for the following types of apps:
Apps that you want to automatically point to dynamic sources, such as product reviews apps and star ratings apps.
Apps that merchants might want to reposition on a page.
Apps that should span the full width of a page.
App block support in themes
Anchor link to section titled "App block support in themes"For app blocks to function, a theme must contain the following:
- JSON templates.
Sections that support and render blocks of type
@app
.Refer to Dawn's main product section for an example implementation.
You can verify whether a theme supports app blocks .
Example app block
Anchor link to section titled "Example app block"The following example creates a span
element with a style
attribute. The style
value (color: {{ block.settings.color }}
) searches inside of schema
for a settings
key, and then searches for a color
key, which contains the "default": "#000000"
value. This value then populates the style
attribute with the default color #000000
, which renders the App blocks let you build powerful integrations with online store themes!
text in black.
Examples of app blocks in a theme
Anchor link to section titled "Examples of app blocks in a theme"The following is an example of an app block added to a section:
The following is an example of a wrapped app block:
Benefits of app blocks
Anchor link to section titled "Benefits of app blocks"App blocks are flexible. Merchants can use the theme editor to add, remove, and reorder app blocks at the section level for easy customization.
An app block can use autofill
resource settings to automatically point to dynamic sources and ensure that content remains in sync with its parent section. For example, an app block on the Products page can point to a dynamic source to show data for different products as they display on the page.
App embed blocks
Anchor link to section titled "App embed blocks"Apps that don't have a UI component, or that add floating or overlaid elements, extend themes using app embed blocks. Shopify renders and injects app embed blocks before HTML </head>
and </body>
closing tags. Create an app embed block by setting the target
in the schema to either compliance_head
, head
, or body
. App embed blocks with compliance_head
will be included first and should be used only when necessary, for example in cookie consent banners.
By default, app embed blocks are deactivated after an app is installed. Merchants need to activate app embed blocks in the theme editor, from Theme Settings > App embeds. However, your app can provide merchants with a deep link, post installation, to activate an app embed block automatically.
Use app embed blocks for the following types of apps:
Apps that provide a floating or overlaid component to a page, such as chat bubble apps and product image badge apps.
Apps that add SEO meta tags, analytics, or tracking pixels.
App embed blocks are supported in vintage and in Online Store 2.0 themes, because they don't rely on sections or JSON templates. However, app embed blocks can't point to dynamic sources, because these blocks only have access to the Global Liquid scope for the page on which they're rendered.
Example app embed block code
Anchor link to section titled "Example app embed block code"
Example of an app embed block in a theme
Anchor link to section titled "Example of an app embed block in a theme"Benefits of app embed blocks
Anchor link to section titled "Benefits of app embed blocks"App embed blocks are supported in vintage and Online Store 2.0 themes. This means any merchant can use your app without you needing to maintain two installation paths: one for vintage themes and one for Online Store 2.0 themes.
After installation, merchants can use the theme code editor to configure app embed block settings for a more customized experience.
App embed blocks allow you to only load scripts on specific pages, which isn't possible with the ScriptTag
object. Loading scripts on specific pages minimizes your app's performance impact by limiting it to only the pages where it's needed.
Conditional app blocks
Anchor link to section titled "Conditional app blocks"You can control the visibility of an app block or app embed block based on a custom condition. For example, you might want to limit content based on plan tier, or geographic location.
The condition can be included in the block's schema with the available_if
attribute, and the state of the condition is stored in an app-data metafield. The metafield can be accessed through the Liquid app
object.
For example, if you had an app metafield with the namespace of conditional
and key of block1
, then you might use the following schema:
The schema for app blocks and app embed blocks is similar to the theme section schema. It supports the following attributes, some of which are unique to app blocks and app embed blocks:
Attribute | Description | Required |
---|---|---|
name |
The title in the theme editor for the app block or app embed block. Keep app block and app embed block names under 25 characters so they fit in the theme editor sidebar. Don't include the title of your app in the name of the block. The title of your app displays below the name of the app block or app embed block in app block pickers, the app embeds panel, and the app details panel. |
Yes |
target |
Where the block is located. The possible values are The value for app blocks is |
Yes |
JavaScript |
A JavaScript file to load from the If the block is present on the page, then you can load this file automatically by adding a If a merchant adds multiple app blocks or app embed blocks that reference the same JavaScript file to a page, then the file is only included once when the page is loaded. |
No |
stylesheet |
A CSS file to load from the If the block is present on the page, then you can load this file automatically by adding a If a merchant adds multiple app blocks or app embed blocks that reference the same stylesheet file to a page, then the file is only included once when the page is loaded. |
No |
enabled_on |
Limit an app block to specific templates and section groups, or limit an app embed block to specific templates. Refer to theme section schema for more details. App blocks and app embed blocks can't be rendered on checkout step pages. You can use only one of |
No |
disabled_on |
Prevent app block from being used in specific templates and section groups, or prevent an app embed block from being used in specific templates. Refer to theme section schema for more details. App blocks and app embed blocks can't be rendered on checkout step pages. You can use only one of |
No |
class |
Additional CSS classes to be included in the wrapping tag element, similar to theme section classes. Theme app extensions will always include the |
No |
tag |
If set, then a tag wraps the block's output. If not set, then the output is wrapped in a |
No |
settings |
Settings that you provide to the merchant for customizing the app block or app embed block. These settings appear in the theme editor when the block is selected. Setting values can be accessed using the settings Liquid object. |
No |
default |
A default setting configuration for the block. Refer to the section schema for an example. |
No |
available_if |
Determines whether the block will be rendered on the storefront and visible in the theme editor. The value must be a reference to an app-data metafield value. If the value of the app-data metafield returns true, then the block is rendered and available in the theme editor. Refer to Conditional app blocks for an example. |
No |
Recommendations
Anchor link to section titled "Recommendations"Review the following recommendations for building theme app extensions:
- Autofill
- Deep linking
- Performance
- Theme editor compatibility
- Detecting app blocks and app embed blocks
autofill
is an app block setting that's automatically set to dynamic sources when merchants add an app block to a section.
App blocks can include settings in the settings
schema object, like sections do. You can give settings that reference resources an additional autofill
attribute. autofill
indicates that Shopify will determine the setting value automatically when merchants add the app block to a section.
autofill
setting values will be set to one of the following sources:
A dynamic source pointing to the parent section's resource setting of the same type.
A dynamic source pointing to the template's global resource.
Autofill example
Anchor link to section titled "Autofill example"A featured product section will have a setting of type product
, which allows a merchant to choose which product to display as featured. An app block that has a product
setting with autofill
set will automatically use the featured product.
In the following example, block.settings.product
will use the section's product
setting:
Deep linking
Anchor link to section titled "Deep linking"Post-installation, your app can provide deep links to help merchants add app blocks or activate app embed blocks directly in a theme. If a merchant clicks a deep link, then they're taken to the theme editor to preview the app block or app embed block before saving.
Deep linking simplifies your app's installation because merchants won't need to navigate to the theme editor, find the block, and then act on it. Instead, your app does the work for them. Merchants can preview the block before saving and have more control over what they include in their online store.
App block deep linking
Anchor link to section titled "App block deep linking"You can implement a deep link to add an app block to the following locations:
- Any JSON template. For example, the
Default product
template. - A header, footer, or aside section group. For example, the
Header
section group. - Any main section that supports app blocks. For example, the
main-product
section. - A specific section that supports app blocks by targeting its ID. For example, the
Newsletter
section on theindex.json
template.
After you add the app block in the theme editor, a coach mark helps the merchant move forward with next steps:
App block deep link query parameters
Anchor link to section titled "App block deep link query parameters"Query parameter | Description |
---|---|
{template} |
The JSON template to which the app block should be added. If not set, then Shopify will default to the index.json template. |
{uuid} |
The ID of the theme app extension. Retrieve the |
{handle} |
The filename of the block's Liquid file. For example, if the Liquid file is located at To see this Liquid file in the context of an app block, refer to the theme app extension getting started sample code. |
{header|footer|aside} |
The section group to which the app block should be added. Only “header,” “footer,” and “aside” are supported. |
{sectionID} |
The ID of the section to which the app block should be added. The Go to JSON templates: Section data for an example of where a section ID can be found in a JSON template file. |
Example URLs
Anchor link to section titled "Example URLs"Your app needs to redirect merchants to a URL with populated parameters.
Adding and app block to any JSON template
The following is the deep link structure for adding an app block to any JSON template in a new Apps section:
For example, the deep link to add the customer_review.liquid
block to the Default product
template might look like the following:
Adding an app block to a section group
The following example shows a deep link structure for adding an app block to the header, footer, or aside section group:
For example, the deep link to add the announcement_bar.liquid
block to the Header
section group might look like the following:
Adding an app block to the main section
The main section is a section with ID="main"
.
The following example shows a deep link structure for adding an app block to the main section of a template:
For example, the deep link to add the star_rating.liquid
block to the main section of the product.json
template might look like the following:
The following example of a theme's product.json
template includes a section with an id
of main
.
Adding an app block to a section using its ID
The following example shows a deep link structure for adding an app block to a section by targeting its ID:
For example, the deep link to add the form.liquid
block to the Newsletter
section of the index.json
template might look like the following:
You can find the parameters for the section you want to target in the template’s JSON file. For example, the parameters of the Newsletter
of the index.json template are shown below:
App block errors and edge cases
Anchor link to section titled "App block errors and edge cases"In the following scenarios, an error message is shown to merchants to guide them with next steps. When possible, you should take steps to prevent these errors.
Error scenario | How to prevent |
---|---|
Section limit has been reached in template or section group |
This error can’t be prevented. The merchant will be invited to remove a section and try again. |
Template is not found |
You can prevent this error by having your app verify the availability of a template, section group, or section with the |
Section is not found |
If the error occurs, the app block will fall back to be added to the template instead. You can prevent this error by having your app verify the availability of a template, section group, or section with the |
Section group is not found |
You can prevent this error by having your app verify the availability of a template, section group, or section with the |
Template type is not supported in app block schema |
You can prevent this error by making sure that your app only deep links to templates that are supported in your app block’s schema. |
Typo in deep link URL |
You can prevent this error by testing deep links to confirm they work and don’t contain typos. |
Template doesn’t have a resource to be rendered |
This error can’t be prevented. The merchant will be invited to create a resource, such as a product, collection, or blog post, and then try again. |
Template is liquid |
You can prevent this error by having your app verify compatibility of a template with the |
Section doesn’t support blocks or app blocks |
If the error occurs, the app block will fall back to be added to the template instead. You can prevent this error by having your app verify compatibility of a section with the |
Block limit has been reached in a section |
This error can’t be prevented. The merchant will be invited to remove a block and try again. |
App embed block deep linking
Anchor link to section titled "App embed block deep linking"You can implement a deep link to activate an app embed block directly in a theme.
App embed block deep link URL query parameters
Anchor link to section titled "App embed block deep link URL query parameters"Query parameter | Description |
---|---|
context |
The context in which the app is being activated. The value is |
{template} |
The templates on which a block is rendered. If not set, then Shopify will default to the index template. The possible values are |
{uuid} |
The ID of the theme app extension. Retrieve the |
{handle} |
The filename of the block's Liquid file. For example, if the Liquid file is located at To see this Liquid file in the context of an app embed block, refer to the theme app extension getting started sample code. |
App embed block deep linking URL
Anchor link to section titled "App embed block deep linking URL"Your app needs to redirect merchants to the following URL, with URL query parameters populated:
You can retrieve the <myshopifyDomain>
value from the Shop
GraphQL Admin API object.
Performance
Anchor link to section titled "Performance"All files inside the assets/
folder are automatically served from Shopify's CDN for fast, reliable asset delivery. Reference your assets by using either the javascript
and stylesheet
schema attributes or using the asset_url
and asset_img_url
Liquid URL filters.
For app embed blocks, take advantage of their ability to only load scripts on specific pages.
Theme editor compatibility
Anchor link to section titled "Theme editor compatibility"You need to ensure that the app works in the theme editor environment. If necessary, you can set your app to detect the theme editor, so that you can adjust your app to work in that environment.
Detecting app blocks and app embed blocks
Anchor link to section titled "Detecting app blocks and app embed blocks"If you want to identify whether a merchant has added app blocks to their theme, or enabled app embed blocks, you can use the Asset
REST Admin API resource to look for blocks that match your app type.
Detecting app blocks
Anchor link to section titled "Detecting app blocks"When a merchant adds an app block to a theme, a reference to the app block is added to the template JSON file.
You can identify your app block by the block type, which uses the following syntax:
An app block is given a unique ID, and the type
value is appended with a unique ID which identifies the app.
The following example contains two app blocks from the same app: one in the main-product
section, and one in an apps
section.
Detecting app embed blocks
Anchor link to section titled "Detecting app embed blocks"App embed blocks appear in settings_data.json
.
An app embed block is added to settings_data.json
only after it's enabled for the first time. If the app embed block is disabled after it's been enabled, then it remains in settings_data.json
, and disabled
is set to true
.
You can identify your app block by the block type, which uses the following syntax:
An app block is given a unique ID, and the type
value is appended with a unique ID which identifies the app.
Reserved prefixes for metafields and metaobjects
Anchor link to section titled "Reserved prefixes for metafields and metaobjects"You can reference reserved namespaces and reserved types for metafields and metaobjects using reserved prefixes in your theme app extension Liquid snippets. This approach eliminates the need to hardcode app IDs and simplifies developing your app for different environments, such as testing and production.
Metafield namespaces
Anchor link to section titled "Metafield namespaces"The following example assumes a metafield value for the key my_key
has been set under a metafield within a reserved namespace $app:custom
. The value can be referenced using the following syntax:
Metaobject types
Anchor link to section titled "Metaobject types"The following example assumes a metaobject definition has been created with a reserved type $app:custom
, and a metaobject has been created with a handle of my_handle
and a field for the key my_key
. The value can be referenced using the following syntax:
File and content size limits
Anchor link to section titled "File and content size limits"Shopify validates theme app extensions when you deploy your extension. If the app's content exceeds any file and content size limits, then the theme app extension fails validation and doesn't update.
The following table provides the enforced, and suggested, limits on theme app extensions:
App content | Limit | Enforced or suggested |
---|---|---|
All files in a theme app extension | 10 MB | Enforced |
Number of blocks | 25 | Enforced |
Number of locale files in the extension | 100 | Enforced |
Size of each locale file | 15 KB | Enforced |
Size of Liquid across all files | 100 KB | Enforced |
Size of CSS (compressed) referenced directly by the schema | 100 KB | Suggested |
Size of JS (compressed) referenced directly by the schema | 10 KB | Suggested |
Restrictions
Anchor link to section titled "Restrictions"The following pages and objects can't be used with theme app extensions.
Theme app extension app blocks and app embed blocks can't be rendered on checkout pages. This includes all pages that are rendered when a customer initiates a checkout, such as Contact information, Shipping method, Payment method, and Order status.
Liquid objects
Anchor link to section titled "Liquid objects"Theme app extensions don't have access to the following Liquid objects or properties:
- The
content_for_header
object - The
content_for_index
object - The
content_for_layout
object - Any properties of the parent
section
object, other thanid
. You can use theid
property to interact with the section rendering API.
Section Liquid Object
Anchor link to section titled "Section Liquid Object"App blocks have access to their parent section liquid object. Only the ID property is accessible, which can be used with the section rendering API.
JSON with comments
Anchor link to section titled "JSON with comments"Theme app extensions do not support comments and trailing commas in JSON like theme files.
- Get started building a theme app extension.