Variables
A variable is a named input of a template: a headline, a price, a photo, an accent colour, a list of rows. You declare it once, bind it into a layer with {{ name }}, and every render passes a new value by name: the Render API, a GET render URL, a bulk row, MCP or the form on the template's page. One template can then produce any number of files without anyone editing the design.
In three steps
- Declare
headline(string) andphoto(image) with default values: in the Variables panel on the Data tab of the editor's right panel (next to Design), or over MCP withsetVariables. - Bind them: a text layer's content is
{{ headline }}, an image layer's source is{{ photo }}. - Render with new values. Anything you leave out keeps its saved value.
curl -X POST https://bannx.com/api/v1/templates/TEMPLATE_ID/render \
-H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{ "format": "png", "variables": { "headline": "Summer sale", "photo": "https://example.com/shoe.jpg" } }'
Variable types
| Type | Stored as (JSON Schema) | What you send | Typical binding |
|---|---|---|---|
string | { "type": "string" } | "Summer sale" | text: {{ headline }} |
number | { "type": "number" } | 3, 19.99 | text, or math: {{ price * 0.8 }} |
boolean | { "type": "boolean" } | true / false | Show if: showBadge |
color | { "type": "string", "format": "color" } | "#6366f1" | fill or stroke: {{ accent }} |
image | { "type": "string", "format": "image" } | an https:// URL or a data:image/… URL | image source: {{ photo }} |
richtext | { "type": "string", "format": "richtext" } | "Save <b>30%</b> today" | text: {{ headline }}. See Rich text variables |
signature | { "type": "string", "format": "signature" } | a PNG/SVG data URL or an image URL | image source. See Signature variables |
code | { "type": "string", "format": "code" } | a string with \n newlines | code layer: {{ code }}. See Code variables |
shader | { "type": "object", "format": "shader" } | { "id": "…", "inputs": { … } } or the id | shader layer. See Shader variables |
array | { "type": "array", "items": { … } } | [{ "name": "Tee", "price": 25 }, …] | Repeat on a row or a scene |
object | { "type": "object", "properties": { … } } | { "name": "Ada", "role": "CTO" } | {{ person.name }} |
Declaring variables
In the editor: open the Variables panel (curly-braces icon), click Edit schema, add fields (string, number, boolean, color, array, object…), then Save & close and set each default under the values. The Preview toggle switches the canvas between resolved values and raw {{ }} tokens; the same switch is Preview values in the editor menu (the logo), shortcut ⇧4. The canvas previews any template with a {{ }} expression, binding, page token, repeat or if, even one with no fields, so use() fallbacks and brand.* colours show as a render would. While Preview is off, a Raw tokens chip in the canvas corner turns it back on. Type {{ in any field that takes an expression and autocomplete lists your variables with their current values (Editor binding reference).
A layer that already reads a name you never declared (say Hello {{ name }}) still renders the value a request sends for it, but nobody sees an input for it. The Variables panel lists such names under Used in this design but not declared: click one, or Add as fields for all of them. A list a layer repeats over is added as an array, an image source as an image, anything else as a string. Check the type and set a default afterwards.
Over MCP: put a setVariables operation first in a create_template or apply_template_ops batch:
{
"op": "setVariables",
"variables": [
{ "name": "headline", "type": "string", "label": "Headline", "default": "Spring launch" },
{ "name": "price", "type": "number", "label": "Price", "default": 49 },
{ "name": "accent", "type": "color", "default": "#6366f1" },
{ "name": "items", "type": "array", "default": [{ "name": "Tee", "price": 25 }] }
]
}
A name starts with a letter or _ and holds only letters, digits and _, up to 40 characters (ctaLabel, price_eur). A label can be up to 80 characters and a description up to 200, and one operation declares at most 40 variables. Re-declaring a name updates it, and remove: ["name"] drops it. A name you bind with {{ }} without declaring it is declared for you as a plain string from its use() fallback, and the result lists it under autoDeclaredVariables. Declare it yourself to get the right type, label and default.
How a template stores them
get_template returns them under templateVariables: a JSON Schema of the inputs, the saved values, and optional samples.
{
"schema": {
"type": "object",
"properties": {
"headline": { "type": "string", "title": "Headline", "default": "Spring launch" },
"accent": { "type": "string", "format": "color", "default": "#6366f1" }
}
},
"values": { "headline": "Spring launch", "accent": "#6366f1" },
"samples": [{ "id": "…", "name": "Black Friday", "values": { "headline": "48 hours only" } }]
}
Older templates may store an array of { id, name, schema, value } instead. Renders read both forms the same way.
A template never stores inline images. A data:image/… default, saved value or sample (PNG, JPEG, GIF, WebP or SVG, at most 20 different images per save) is uploaded to your space's media library when you save, and the template keeps the file's URL. A save request is capped at 5 MB, and base64 adds about a third, so the inline images in one save can total about 3.5 MB; for larger pictures, upload them to the media library first (MCP upload_media) and put the URL in the variable. These uploads count toward your storage like any other upload. Saving the same image again reuses the file already in your space rather than storing a copy. A save is refused if the bytes are not one of those image types, if an SVG contains scripts, or if the space is out of storage. Inline images you send in variables with a render are not stored: they are used for that render only.
Overriding at render time
Send variables, a flat object keyed by variable name. A value you send wins over the saved value, which wins over the schema default. Anything you don't send keeps the template's saved value.
| Surface | How to pass values |
|---|---|
POST /api/v1/templates/:id/render | "variables": { "headline": "…", "count": 3 } in the JSON body. See the Rendering API. |
GET /api/v1/templates/:id/render | Every query key that is not a render option is a variable: ?headline=Hello&count=3. true, false and plain numbers arrive as booleans and numbers. Use var.<name>= (or variables[<name>]=) when a name collides with an option such as scale or format, or pass variables= as a JSON object string. |
| Bulk | One row per file, keyed by variable name: POST /api/v1/templates/:id/bulk with up to 500 rows, or a CSV whose header row is the variable names on the template page's Bulk tab. An object or list variable takes dotted columns (to.name, items.0.qty) or a JSON cell; parts a row leaves out keep their saved values. |
| MCP | render_template { variables: { … } }. |
Overrides are applied before the document is resolved, so every {{ }} expression, Repeat and Show if sees the final values. Brand tokens ({{ brand.* }}) are not variables: switch the brand for one call with brand, or pass brandTokens (see Brands).
Limits: a Repeat expands at most 500 items (the rest of the list is ignored), and a design that resolves to more than 20,000 layers in all is refused with a VALIDATION error. Shorten the collections it repeats over. An inline data:image/… value can be up to 15 MB decoded.
Scopes
| Scope | Where defined | When used |
|---|---|---|
| Template variables | On the template (editor's Variables panel) | Every scene of that template, and the keys a render request may override |
| Brand tokens | On the brand ({{ brand.* }}) | Resolved from the template's brand, else the space default. Changed per call with brand / brandTokens, not with variables |
brand is reserved. When the template has a brand, {{ brand.* }} always reads the brand tokens, even if a variable is called brand. The renderer also provides item, index, page, pages, pageNumber and totalPages, and credential (the verified document a render issues; a credential value in variables is ignored). Pick other names so it is clear which value an expression reads.
Lists
An array variable drives a repeated layer or a repeated scene. Set Repeat to the list (items) and As to a name for one item (item). Inside, {{ item.name }} and {{ index }} resolve per copy. Repeat a scene and each item becomes a page. An empty list renders nothing for that layer; the editor still lists it in Layers (dimmed, loop count 0) so you can select it and fix the expression. See Pages from data and Loops.
{ "variables": { "items": [ { "name": "Tee", "price": 25 }, { "name": "Cap", "price": 18 } ] } }
Samples
Up to 10 named value sets kept beside the variables (Samples → + Add in the Variables panel, setVariables { samples } over MCP). They preview on the template page and in the public gallery, and render with variables: sample.values. The whole list stays under 48 KB. They are examples, not a data table: use bulk rows or a Content collection for real data.
Hidden helper variables
Some variables drive expressions but aren't inputs, such as the step-by-step strings behind a typing effect or a lookup table. Mark them hidden: true on the variable's schema property. Over MCP, use setVariables { variables: [{ name, type, default, hidden: true }] }.
A hidden variable:
- is left out of the template page form, the bulk CSV columns, the example request bodies and the template's markdown docs;
- still resolves in every
{{ }}expression,repeatandif; - can still be overridden by an API caller who knows its name.
The editor's Variables panel keeps showing hidden variables and lists them under the form. get_template returns them with hidden: true. To show a variable again, set hidden: false.
Common problems
| Symptom | Cause and fix |
|---|---|
| A value you send changes nothing | No layer reads the variable (it is unbound), or the name differs (names are case-sensitive). Publish in the editor and create_template / apply_template_ops warn about unbound variables. |
| A new variable is ignored by the API | The Render API renders the published snapshot. Bindings added since the last publish are not in it. Publish again, or pass "draft": true. |
| An image layer renders as a flat colour | The URL could not be loaded. The response's warnings names the layer, and says when the link returned a web page (a sign-in page or a share page) instead of the file. Use a public https:// image URL or a data:image/… URL. A Google Drive or Dropbox share link works in renders (API, bulk, signed URLs): bannx fetches the file behind it, as long as the file is shared with "Anyone with the link". The editor canvas may not preview a share link, so upload the image to the media library when you need to see it while designing. |
?zip=007 arrives as 7 | GET query values that look like numbers become numbers. Send strings like this in a POST body. |
?scale=2 changed the resolution, not your variable | scale is a render option. Use ?var.scale=2. |
422 VALIDATION on a long list | The design resolved to more than 20,000 layers. Trim the list or split the render. See Errors. |
| An optional field shows blank | Wrap it in a fallback: {{ use(ctaLabel, "Get started") }}. A saved empty string counts as not set. |
FAQ
Do I have to send every variable? No. Send only what changes. The rest keeps the saved values.
What happens to a key the template does not declare? It is accepted and has no effect unless a layer reads that name.
Can a variable change the brand? Not through variables. Use the brand or brandTokens render fields.
Where do I see a template's variables? The template's API tab shows a sample request with them, get_template over MCP returns the schema, and /openapi.json documents the render endpoint.
Related: Template expressions · Editor binding reference · Templates · Rendering API