Structure

Learn about the structure of a theme app extension and how to configure it.


Directory structure

The standard directory structure for a theme app extension is as follows:

└── theme-app-extension
├── blocks
│ ├── app-block.html
│ ├── app-embed-block.html
│ ├── conditional-app-block.html
│ └── ...
├── components
│ ├── logo-icon.html
│ └── ...
├── i18n
│ ├── en.json
│ ├── en.schema.json
│ ├── zh-hans-cn.json
│ ├── zh-hans-cn.schema.json
│ ├── zh-hant-tw.json
│ ├── zh-hant-tw.schema.json
│ └── ...
├── public
│ ├── app-block.css
│ ├── app-block.js
│ ├── app-embed-block.css
│ ├── app-embed-block.js
│ └── ...
└── .shopline-cli.yml

Descriptions for different directories and files are as follows:

Directory or fileDescription
blocksHTML files for App Blocks and App Embed Blocks.
componentsSnippets of code for the theme app extension that can be referenced and reused within App Blocks and App Embed Blocks.
i18nJSON files for multi-language support, storing translations for merchants and customers. These are used similarly to theme locale files.
publicCSS, JavaScript, and other static resources. They can be included using the javascript and stylesheet properties in the schema, or with the asset_url filter.
.shopline-cli.ymlConfiguration file for the theme app extension.

App Block

App Blocks allow merchants to add blocks from the app into theme sections.

By default, App Blocks are not automatically added after installing an app. Merchants need to add App Blocks using the theme editor manually.

The following example creates a simple <span> element with a style attribute. For detailed configuration in the schema tag within the example, refer to Schema.

<span style="color: {{ block.settings.color }}">
App Block
</span>
{{#schema}}
{
"name": "App Block",
"target": "section",
"stylesheet": ["public/app.css"],
"javascript": ["public/app.js"],
"settings": [
{
"label": "Color",
"id": "color",
"type": "color",
"default": "#000000"
}
]
}
{{/schema}}

The following shows examples of adding an App Block within a theme section and an independent App Block in the theme.

App Block in a theme sectionAn independent App Block

App Blocks are flexible, allowing merchants to add, remove, and sort them at the section level in the theme using a visual editor.


App Embed Block

App Embed Blocks enable merchants to add UI-less features or global floating elements on a page from the app into the theme. They are suitable for the following types of apps:

  • Apps that provide floating elements on the page, such as customer service chat apps and announcement notification apps.
  • Apps that add SEO meta tags, analytics, or custom forms.

You can set the target property in the schema to either head or body to determine where the App Embed Block is injected. By default, App Embed Blocks are not automatically activated upon installation. Merchants need to activate them from Theme settings > App embeds in the theme editor.

The following example demonstrates an App Embed Block being inserted at the bottom of the <body>, rendering a button that floats at the bottom of the page.

<div style="position: fixed; bottom: 0; right: 0">
<img src="{{ `comment.jpg` | asset_url() }}" />
</div>
{{#schema}}
{
"name": "App Embed Block",
"target": "body",
"settings": []
}
{{/schema}}

The following shows an example of the floating button rendered on the page.


Schema

The schema for App Blocks and App Embed Blocks is similar to the theme section schema and supports the following attributes. Some attributes are unique to App Blocks and App Embed Blocks.

Attribute nameTypeRequired or notDescription
namestringYesTitle of the App Block or App Embed Block in the theme editor. Recommended to be within 25 characters to fit the theme editor sidebar.
targetstringYes

Position on the page where the App Block or App Embed Block is rendered.

App Blocks support the value section, indicating rendering in the theme section.

App Embed Blocks support the following values:

  • head: indicates in the <head> tag of the page.
  • body: indicates in the <body> tag of the page.
stylesheetarrayNoCSS files to load from the public directory.
The path must include the public prefix, for example, public/app.css.
rtl_stylesheetarrayNo

RTL CSS files to load from the public directory.
The path must include the public prefix, for example, public/rtl-app.css.

CAUTION

This attribute only takes effect when the language is set to ar (Arabic). If rtl_stylesheet is not provided for ar, the stylesheet attribute will be used as a fallback.

javascriptarrayNoJavaScript files to load from the public directory.
The path must include the public prefix, for example, public/app.js.
The injected <script> tag will automatically include the defer attribute.
resourceobjectNo

An object for integrated resource management, providing more granular control over resource loading.
If this attribute is defined, the stylesheet, rtl_stylesheet, and javascript attributes will be ignored.
Example:

{   
"resource": {
"css": [
{
"src": "public/app.css"
}
],
"rtl_css": [
{
"src": "public/rtl_app.css"
}
],
"js": [
{
"src": "public/app.js"
}
]
}
}
resource.cssarrayNo

Array of CSS resource configurations.
Attributes:

  • src (required): The CSS file to load from the public directory.
  • preload (optional): Whether to preload the resource.
    • true: Preloads the resource.
    • false (default): Does not preload the resource.
  • position (optional): Resource injection position.
    • "header" (default): Injected within {{#content "header" /}}.
    • "footer": Injected within {{#content "footer" /}}.
resource.rtl_cssarrayNo

Array of RTL CSS resource configurations.
Attributes:

  • src (required): The CSS file to load from the public directory.
  • preload (optional): Whether to preload the resource.
    • true: Preloads the resource.
    • false (default): Does not preload the resource.
  • position (optional): Resource injection position.
    • "header" (default): Injected within {{#content "header" /}}.
    • "footer": Injected within {{#content "footer" /}}.
CAUTION

This attribute only takes effect when the language is set to ar (Arabic). If resource.rtl_css is not provided for ar, the resource.css attribute will be used as a fallback.

resource.jsarrayNo

Array of JavaScript resource configurations.
Attributes:

  • src (required): The JavaScript file to load from the public directory.
  • preload (optional): Whether to preload the resource.
    • true: Preloads the resource.
    • false (default): Does not preload the resource.
  • position (optional): Resource injection position.
    • "header" (default): Injected within {{#content "header" /}}.
    • "footer": Injected within {{#content "footer" /}}.
  • loadStrategy (optional): Resource loading strategy.
    • "sync": Synchronous loading
    • "async": Asynchronous loading
    • "defer" (default): Deferred execution
templatesarrayNo

Templates where the App Block or App Embed Block can be injected. Defaults to all pages if not set.
Valid values are:

  • index
  • collections_all
  • collection
  • product
  • cart
  • blog
  • article
  • 404
  • search
  • page
  • policy
  • password
  • gift_card
  • customers/login
  • customers/register
  • customers/account
  • customers/addresses
  • customers/orders
  • customers/order
  • customers/activate_account
  • customers/forgot_password
  • customers/company
classstringNo

Additional CSS classes to include in the wrapper element, similar to the class attribute in theme sections.
The theme app extension includes the shopline-block class by default.

CAUTION

This attribute is not applicable when the App Embed Block's target value is head.

tagstringNo

Tag used to wrap the block output, defaults to div.
Valid values are:

  • article
  • aside
  • div (default)
  • footer
  • header
  • section
CAUTION

• App blocks do not support the configuration of this attribute.
• This attribute is not applicable when the App Embed Block's target value is head.

settingsarrayNo

Configuration options for the App Block or App Embed Block. For configuration details, refer to settings in sections.

limitintegerNoLimit on the number of App Blocks or App Embed Blocks that can be added into the theme section.
Was this article helpful to you?