App blocks
Put your app's UI inside a store's pages as a block the merchant places in the theme editor, with merchant settings, files Tanqory serves from the store's own address, and the tqAppBlocks mount API.
An app block is your UI inside a section of a store's page. The merchant adds it in the theme editor like any block of the theme, fills in your settings and moves it where it fits. On the page, Tanqory writes an empty placeholder with the settings, loads your script and stylesheet from the store's own address, and your script fills the placeholder in the shopper's browser.
Use a block for anything that belongs in the page. For a floating button or a script that runs on every page, use an app embed; Theme app extensions compares the two and lists the review rules.
How it reaches the page
- Merchant (theme editor) → Tanqory Adds your block to a section and fills in its settings
- Tanqory → Shopper's browser The page, with the placeholder, your stylesheet and your script from the store's own address
- Shopper's browser Your script registers, then mounts into each placeholder with its settings
Your files are uploaded with the app version and stored under their SHA-256, so the file a reviewer read is the file shoppers get. They are served from the store's own address, which is what the store's security policy allows, and cached for good: a change is a new file with a new name in a new version.
1. Write the script
Register each block once, when your script first runs:
// blocks/booking.js
window.tqAppBlocks.register('booking', {
mount(root, settings, info) {
// root: an empty element of yours inside the block's placeholder
// settings: the merchant's values for this block, as an object
// info: { type: 'app:<app>/booking', id, element } (element is the placeholder)
const box = document.createElement('div');
box.className = 'booking';
const title = document.createElement('h3');
title.textContent = settings.heading ?? 'Check availability';
box.append(title);
root.append(box);
},
unmount(root) {
// optional: stop timers and listeners; root is removed after this
},
});| Part | What it is |
|---|---|
register(name, block) | name is the block's handle, or its full type app:<app>/<handle>. Returns true, or false when that type is already registered. |
mount(root, settings, info) | Runs once for each placeholder of this block on the page, and again for each one the editor adds or redraws. root is a new, empty element appended inside the placeholder: render into it and nowhere else. |
unmount(root) | Optional. Runs when a placeholder leaves the page, for example when the merchant changes a setting in the editor (the block is drawn again and mounted again with the new values). |
Keep these in mind:
- Call
registerwith the handle while your script first runs. The short name is matched to your app through the script tag that is running; from a callback or a timer, pass the full typeapp:<app>/<handle>instead. - One placeholder, one mount. A merchant may add the block twice on a page; each gets its own
rootand settings. - A mount that throws is logged in the console and leaves only that block empty; the rest of the page carries on.
- Read the page, not the theme. The page address (
location.pathname, such as/products/<handle>) tells you which product or collection the page is about. Do not look up the theme's elements: the merchant decides where your block sits. - Talk to your server through the app proxy on the store's own address (
/apps/<subpath>/...). The store's security policy refuses calls to other addresses, and iframes. - Style only your own elements. Use a class of your own on everything you render and inherit the theme's fonts and colours. Your stylesheet is loaded in the page head.
2. Declare the block
A block has a handle, a name, the script, an optional stylesheet and the settings the merchant fills in. Declare it in tanqory.extensions.json and push it with the tanqory-partner command line, which uploads both files first:
{
"app": "<your app id>",
"themeAppBlocks": [
{
"handle": "booking",
"name": "Booking form",
"description": "Dates and free rooms, under a room's details.",
"icon": "https://cdn.example.com/booking-icon.png",
"script": "blocks/booking.js",
"style": "blocks/booking.css",
"settings": [
{ "key": "heading", "type": "text", "label": "Heading", "default": "Check availability" },
{ "key": "maxNights", "type": "range", "label": "Longest stay", "min": 1, "max": 30, "step": 1, "default": 14 },
{ "key": "layout", "type": "select", "label": "Layout", "options": [{ "value": "stacked", "label": "Stacked" }, { "value": "inline", "label": "In one row" }], "default": "stacked" }
],
"targets": ["section"],
"requires": ["product"]
}
]
}tanqory-partner app extensions check
tanqory-partner app extensions push| Field | Rules |
|---|---|
handle | 1 to 64 lower-case letters, digits or hyphens, starting with a letter or digit; unique in the app. Themes keep the block by it. |
name | What the merchant sees in Add block, at most 100 characters. |
description | One line for the block picker, at most 500 characters. |
icon | An https image for the block picker. |
script | Required. JavaScript, UTF-8, at most 64 KiB. |
style | CSS, UTF-8, at most 100 KiB; no @import, expression( or javascript:. |
settings | At most 25. See below. |
targets | Where the merchant may add it: section (directly in a section), block (inside another block), or both (the default). A theme save refuses it anywhere else. |
requires | The kinds of page it is for, such as product. Add block offers it only on those pages, and a theme save refuses it on any other. |
The partner dashboard's Extensions, Add app block does all of this too, settings, icon, where it goes and its pages included, and Edit on a row changes a block you have.
Settings
Each setting is { key, type, label } with optional info (help under the field, at most 300 characters), default, and for some types options, min, max, step.
type | The merchant gets | Extra fields |
|---|---|---|
text, textarea, richtext | Text | default at most 1000 characters |
url | An address | |
color | A colour | |
boolean | A switch | |
select | A list | options: 1 to 50 { value, label } |
range | A slider | min and max (required), step |
number | A number | min, max, step |
image | An image from the store's files | |
product, collection | A product or collection of the store |
key starts with a letter and has up to 64 letters, digits or _. When the merchant adds the block, each setting starts at its default. The theme editor checks the merchant's values against your settings when the theme is saved.
Through the API
The command line calls the Partner GraphQL API. For each file, partnerAppBlockAssetUploadCreate(input: { appId, kind: SCRIPT | STYLE, name, sha256, fileSize }) answers a grant that lasts 5 minutes: send the file's bytes as the body of POST <url> with Authorization: Bearer <token>. The answer's path (<name>-<first 8 hex of the SHA-256>.js or .css), sha256 and bytes go into the block's script or style in partnerAppUpdate(id, input: { themeAppBlocks: [...] }).
| Refusal | Why |
|---|---|
file_too_large | More than 64 KiB (script) or 100 KiB (stylesheet) |
size_mismatch, hash_mismatch | The bytes sent are not the ones the grant names |
invalid_file | Not UTF-8, a NUL byte, or a refused CSS construct |
malware_detected | The malware scan found something |
invalid_grant | The grant expired (5 minutes) or is for another file |
invalid_parameter | In partnerAppUpdate: the field path says which, such as themeAppBlocks.0.script.path |
Uploads are limited to 120 grants an hour per app.
3. Try it on a development store
- Install the app on a development store.
- In the store dashboard, open Online Store, Themes, and Customize on a theme.
- Open a page with a section that accepts app blocks (in Tanqory's Nova theme: product details, rich text, group and stack), select Add block, then the Apps tab, and pick your block. The editor's preview runs your script, so you see the block and each setting change.
- Save, publish or preview the theme, and open the page.
A section shows the Apps tab only when the theme lets it take app blocks. Theme developers: list @app among the blocks a section or block accepts; it is not allowed on layout components such as the header and footer, or in presets.
Limits
| Blocks per app | 30 |
| Settings per block | 25 |
| Script | 64 KiB |
| Stylesheet | 100 KiB |
| App blocks per store, all apps | 200 |
When the app is uninstalled
Your blocks leave every theme of the store, recorded in each theme's history as removed because the app was uninstalled, so the merchant can restore them after reinstalling. Until that change reaches a theme, the editor shows your block as not available.