Skip to content

Template language reference ​

Every Onivos template — website pages, layouts and modules, email and marketing messages, PDF documents, AI prompts and automation fields — is written in one language: HubL-flavoured Jinja. A template never fetches: what it reads is declared at the top with {% data %} and loaded before it renders; every render is bounded in time and work; and every value is escaped for where it lands. Anything not on this page does not exist — a name from Liquid, Jinja or HubL that Onivos leaves out fails at save with the replacement named.

1. Principles ​

P1 — One obvious way. Two constructs for one job are a bug in the language: every synonym is a fork an author or an LLM takes, and a round-trip in the MCP authoring loop. Where Jinja and HubL both offer two ways, one is kept and the other fails at save with the replacement named (§11).

P2 — Data is declared, then rendered. A template never fetches. What it reads is declared at the top with {% data %} (§8), checked at save, and loaded before the render starts. The render itself does no I/O.

P3 — Bounded by construction. Every render runs under a fuel budget and a wall-clock deadline enforced inside the interpreter, and every builtin is O(size of its input) with that size capped (§10). The longest step the interpreter cannot interrupt is a measured, test-pinned constant. A builtin that cannot meet this does not ship — which is why there is no regex filter.

P4 — Names. Jinja's name for core behaviour; HubL's where Onivos semantics match; an Onivos name only where the semantics are Onivos's own (money takes minor units, HubL's currency formatter does not). HubSpot structure tags keep their HubL names and shapes.

P5 — Escaped for the context. In html mode every output is escaped for where it lands — text, attribute, URL, script, style, tag/attribute name (§7) — markup included. |safe is the only opt-out, and never from the URL check.

P6 — Deterministic. The same template and data render the same bytes (pages are cached). No randomness, no clock without an explicit timezone and format.


2. Lexical structure ​

ElementFormNotes
Output{{ expr }}
Statement{% name … %}
Comment{# … #}never output; may span lines
Whitespace control{%- -%} {{- -}}strips whitespace on that side up to the next non-space character, newlines included
Raw text{% raw %}…{% endraw %}emitted verbatim, delimiters and all
String"…" or '…'escapes: backslash + n t r \ ' ", and backslash + u + 4 hex digits
Number42 -7 3.14 1e3 1_000IEEE-754 double; integers exact to 2^53
Constantstrue false noneTrue/False/None accepted (Jinja habit), lowercase is canonical
Identifier[A-Za-z_][A-Za-z0-9_]*case-sensitive

Template files use .html (HubL's convention).


3. Values ​

TypeTruthy whenNotes
nonenever
booleantrue
number≠ 0nan is falsy
stringnon-emptyUTF-16 length is what the limits count
listnon-emptyordered
dictnon-emptyinsertion-ordered; keys are strings
undefinednevera missing variable, attribute or index; renders as '', chains leniently (a.b.c of a missing a is undefined, not an error)
unavailablenevera {% data %} result that could not be loaded and has no stale copy (§8.5); iterates as empty, renders as '', and is what is unavailable detects
markupas its texttext already escaped for HTML (the result of `

Data is immutable. Every value that comes from the ambient scope or a {% data %} declaration is read-only. Lists and dicts a template builds itself (literals, filter results) are mutable through {% do %} (§5.6) and nothing else.

Display (what {{ x }} prints) follows HubL rather than Python: true/false, none and undefined as '', a number in its shortest form (2, not 2.0 — there is one number type), a list or dict as compact JSON. round rounds half away from zero (2.5 → 3, HubL/Java's HALF_UP), not Python's half-to-even. The integer/float tests judge the value (2.0 is integer).

Equality (==) compares by value (deep for lists and dicts, charged like any other traversal). Ordering (< …) is defined between numbers and between strings; anything else is a runtime error (§10.3).


4. Expressions ​

Precedence, lowest first — Jinja's, verified against Jinja2 3.1.6:

LevelOperators
1a if cond else b (the else may be left out: undefined)
2or
3and
4not
5in not in == != < <= > >= (comparisons chain: a < b < c)
6~ (string concatenation, both sides stringified)
7+ -
8* / // %
9** (left-associative, as in Jinja)
10filters |f(…) and tests is t(…) / is t arg — applied to the operand on their left
11a sign -x +x (binds tighter than a filter: -1|abs is (-1)|abs)
12postfix: .attr [key] [a:b:c] call (…)
  • Arithmetic follows Python/Jinja: / is true division, // floors, % takes the sign of the divisor, ** is left-associative. Division by zero is a runtime error. + concatenates two strings or two lists; * repeats a string or list by an integer (both charged against the limits).
  • Lookup: a.b and a["b"] are the same on a dict; a[0], a[-1] index a list; slices a[1:3], a[::-1] work on lists and strings. Own data only — there is no prototype, no method table, nothing reachable that the data did not contain.
  • Calls are limited to: macros, caller(), super(), range(), namespace(), loop.cycle(), loop.changed(), the read methods dict.items() / .keys() / .values(), and the mutation methods of §5.6 inside {% do %}. Nothing else is callable.
  • Literals: [1, 2], {"k": v} (string keys), (1, 2) is a list.

5. Statements ​

5.1 Variables ​

StatementMeaning
{% set x = expr %} / {% set a, b = pair %}bind (unpacking a list of the same length)
{% set x %}…{% endset %}capture rendered output into x as markup
namespace(count=0) + {% set ns.count = … %}the one way to carry a value out of a loop

Scoping is Jinja's: a set inside for, if bodies of a loop, a macro or an included template does not leak out of it. namespace() is the explicit escape hatch — no hidden second namespace.

5.2 Control flow ​

StatementNotes
{% if %} {% elif %} {% else %} {% endif %}
{% unless %} {% else %} {% endunless %}HubL
{% for x in seq %} … {% else %} … {% endfor %}else renders when nothing iterated; for k, v in d.items() unpacks; for x in seq if cond filters
{% break %} {% continue %}innermost loop

loop inside a for: index index0 revindex revindex0 first last length previtemnextitem cycle(a, b, …) changed(value). (No recursive loops, so no depth.)

5.3 Reuse ​

StatementSemantics
{% macro card(title, url="#") %}…{% endmacro %}positional + keyword arguments with defaults; returns markup; sees its template's top-level names and its arguments, never the caller's locals
{% call card("x") %}body{% endcall %} / caller()pass a body to a macro
{% import "macros/cards.html" as cards %} · {% from "macros/cards.html" import card, badge as b %}the imported template runs without the caller's context (its top-level sets and macros only)
{% include "snippets/price.html" %}renders the partial with the current context, read-only (its sets do not leak back); ignore missing allowed; without context isolates it

Paths resolve against the site's own template set only (an in-memory map — never a disk, never another site). A cycle in the include/import/extends graph is refused at save; nesting is bounded at render (§10).

5.4 Inheritance ​

{% extends "layouts/base.html" %} (first statement of the template, one per template) · {% block name %}default{% endblock %} · {{ super() }} inside an override. A child's content outside blocks is not rendered (Jinja semantics). The layout chooses where page content goes by its blocks; the new-page scaffold fills the layout's content block with a dnd_area.

5.5 Page structure (HubL) ​

StatementNotes
{% dnd_area "main" %}…{% end_dnd_area %}a drag-and-drop region in coded markup; its body is the live content the builder edits
{% dnd_section %}…{% end_dnd_section %}a full-width row with section styling (background, padding, max_width)
{% dnd_row %}…{% end_dnd_row %}a 12-column grid row
{% dnd_column width=6, offset=0 %}…{% end_dnd_column %}width 1–12, offset 0–11 — HubL's grid (replaces today's free weights)
{% dnd_module path="hero", heading="…" %}{% end_dnd_module %}a module instance inside an area (HubL's block form; the body stays empty in v1); the remaining arguments are its field values
{% module "promo" path="hero", heading="…" %}a module instance outside any area (fixed in the layout, still editable)
{% global_partial path="globals/header.html" %}the site's global section by path
{% require_css %}…{% end_require_css %} / {% require_js %}…{% end_require_js %}hoisted to <head> / end of <body> once, deduplicated by content hash

Tag arguments are name=value separated by commas (a trailing comma is allowed). Every module's fields are a JSON Schema in its definition (unchanged from today); unknown field names are a save error.

What the builder edits: inside an area, a dnd_module, dnd_row and dnd_column whose arguments are all literals is an element; everything else — markup, control flow, dnd_section, a tag written with an expression — is opaque code the canvas moves as one block. The builder writes a canonical form (arguments id, path, fields sorted, styles last; a row's widths whole spans filling 12 columns with its offsets) and owns the tag text it writes: an id-less dnd_module/dnd_row/module gets its id on save. An offset skips columns from where the previous column ended; on small screens the columns stack and offsets drop.

5.6 Mutation ​

{% do x.append(v) %} · {% do x.extend(list) %} · {% do d.update({"k": v}) %} — on values the template built itself (§3); on declared or ambient data they are a runtime error. Each call is charged like the allocation it is.

5.7 Data ​

{% data name = source.method(arg=value, …) %} — §8.


6. Builtins (v1) ​

Every entry is O(n) in its input, charged to the fuel meter by the work it does, and bounded by the limits of §10. Columns: name · what it does · Jinja / HubL / Onivos origin.

6.1 Filters ​

The engine ships Jinja's core and the Intl-backed formatting; filters that rest on a platform helper — slugify, striptags and sanitize_html, money, t, image_url/image_tag/image_srcset, asset_url/stylesheet_tag/script_tag, class_names — are registered by the host environment, so each rule keeps its single home. Both kinds are the dialect; an author cannot tell them apart.

GroupFilters
Stringupper lower capitalize title trim replace(old, new, count) split(sep, max) truncate(length, killwords, end) wordcount striptags slugify urlencode urldecode (HubL — + is a space) center✗ indent✗
Markup (return markup)safe · sanitize_html (HubL — allowlist sanitizer for rich text not sanitized at the normalizer) · truncatehtml(length, end) (HubL — tag-aware, closes what it opened) · newline_to_br (escapes its input, emits only its own <br>)
Numberabs round(precision, method) (method: common/ceil/floor) int(default) float(default) format_number(decimals) (HubL — locale-aware grouping) filesizeformat
Moneymoney(currency) money_with_currency(currency) (Onivos — integer MINOR units in; currency from the site/commerce scope unless given; locale = the store's business locale, site.money_locale — one format on every page language, as the storefront DTOs — else the page)
Listfirst last length join(sep, attribute) sort(reverse, case_sensitive, attribute) reverse unique(attribute) map(attribute=…) map(filter_name, …) select(test) reject(test) selectattr(attr, test, …) rejectattr(…) groupby(attribute) batch(size, fill) slice(slots) sum(attribute, start) min(attribute) max(attribute) list dictsort(by, reverse) items · union(other) intersect(other) difference(other) symmetric_difference(other) (HubL — each value once, by value, in the left list's order then the right's)
Dateformat_date(format, timezone, locale) format_time(…) format_datetime(…) (HubL — named formats short/medium/long/full or a pattern; timezone defaults to the site's) · datetimeformat(strftime, timezone) · plus_time(n, unit) minus_time(n, unit) between_times(end, unit) (HubL — unit one of seconds … weeks exact, months/years calendar units in UTC: a shifted day clamps to the month's last, a difference counts whole units as Java's time API does) · unixtimestamp (epoch milliseconds)
Datadefault(value, boolean) · tojson (in a <script> it is embedded as the JSON it is — §7) · fromjson (JSON text → read-only value, held to the list caps) · string
Localelocale_name(locale) (HubL — a language code's name in locale, else in itself: "vi"|locale_name → Tiếng Việt)
Media & assetsimage_url(width=, size=) image_tag(alt=, sizes=, fetchpriority=) image_srcset(sizes=) asset_url stylesheet_tag script_tag (Onivos — the media-derivative and fingerprinted-asset contracts are unchanged from today)
i18nt(default=…, **params) (Onivos — the theme locales/ catalog)
Classesclass_names (Onivos — conditional class joiner)

✗ = not shipped (P1/P3: no real use in a CMS, or a cheaper way exists).

6.2 Tests (x is t) ​

defined undefined none boolean number integer float string mapping sequenceiterable even odd divisibleby(n) in(seq) eq ne lt le gt ge lower upper · containing(x) containingall(list) string_startingwith(prefix) (HubL — containing is in reversed, for selectattr('tags', 'containing', 'news')) · unavailable (Onivos — §8.5). The comparison tests exist for select/selectattr; in an expression, write the operator.

6.3 Functions ​

range(start, stop, step) (length capped) · namespace(**values) · super() · caller() · loop.cycle() · loop.changed(). Nothing else: a function that reads data is a {% data %} source (P2), and a function that formats data is a filter.


7. Escaping (html mode) ​

The compiler knows the HTML context of every output when it compiles the template and emits the escaper for it:

ContextEscaping
Text, quoted attributeHTML-escaped (& < > " ')
Unquoted attributeHTML-escaped + whitespace, = and backtick as character references
URL attribute (href, src, action, …, and an SVG animation's to/from/by/values — each ; entry)a script-capable scheme (javascript:, vbscript:, non-image data:; data:image/svg+xml outside an image element — an <iframe>/<object>/<use> loads it as a document) becomes about:invalid#onv-unsafe-url — judged across literal text and outputs (java{{ x }} counts); then HTML-escaped
<script> body / on* attributeinside a string, template literal or regex: backslash-u escapes for every character that could end it (an empty regex value is (?:), never //); in operand position: a JS literal (numbers stay numbers, tojson output is embedded as-is with < > & escaped — JSON-LD stays valid); plus HTML encoding inside an attribute
<style> body / style attributea value that could leave its declaration ({ } < backslash, comments, expression(, -moz-binding, a ; outside a string or parentheses) becomes onv-unsafe-css — several declarations come only from the host (style_inline); strings and unquoted url() get CSS escapes
Tag / attribute namemust stay a plain name (never a script/style/raw-text element, an SVG animation, an event handler, a URL or style attribute) — else onv-unsafe; inside <svg>/<math> a tag name from a value is refused at save
srcdocHTML-escaped twice
Comment, <!…>, SVG <![CDATA[HTML-escaped with - ! ] as references (an empty value is a space), so a value never closes it
Raw text (<title>, <textarea>, <noscript>, a non-JS <script>)HTML-escaped; markup has its own end tag (</title) neutralized

The scanner reads markup as a browser's tokenizer does — a value escaped for a context the page is not in is the one way past this table, so the model follows the HTML spec where a naive one parts from it: only HTML whitespace delimits names; comments also close at <!-->, <!--->, --!>; every JavaScript MIME type a browser runs is a JS body (text/x-javascript, text/jscript, … with or without parameters); <noscript> is raw text (scripts run only where it is); <!--<script> inside a script keeps the next </script> from ending it; inside <svg>/<math> nothing is raw text except at an HTML integration point, an HTML-only tag breaks out, and an SVG <script>/<style> body — markup there — is refused at save if it holds < before a letter, /, !, ? or a character reference.

Markup (captured/macro output, a markup-producing filter, |tojson, |safe) is text already safe as HTML, so it is emitted as-is only where the browser parses HTML — element text. Everywhere else its text is escaped for the context like any value's: a captured javascript: link still meets the URL check, a macro's output in operand position becomes a JS string, |tojson in a double-quoted attribute has its " encoded, markup in an unquoted attribute or srcdoc is attribute-encoded, and markup in a tag's attribute position must be a list of plain attributes (class="…", srcset="…" — never on*, style, a URL or srcdoc). Two kinds keep their meaning outside HTML: |tojson is a literal in script operand position, and |safe — the author's explicit vouch — is raw in script and style and in attribute position. |safe never lifts the URL scheme check or tag-name validation.

An {% include %}, {% block %}, {% call %} or extension tag is a hole too: in an attribute or a tag its output goes through that site's escaper as markup, and inside a <script>, a <style> or an on*/style attribute it is refused at save — its output is HTML, which the escaper can only turn into a string there; the element belongs inside the template it renders.

Every path agrees on the context (Go's html/template rule). Each branch of an if is scanned from where the if starts and the branches must end in one context; a for body must end — and break/continue — in the context it starts in (checked to a fixpoint: the second iteration starts where the first ended); a macro, {% call %} or {% set %}…{% endset %} body is scanned on its own and must end in element text; a template must end in element text. Otherwise it is refused at save with the position. Paths that differ only where the escaper stays safe are joined instead: an optional attribute ({% if c %} selected{% endif %}) — as long as whitespace, / or > follows — a class toggled inside a value, a script type set by a branch (read as JS), a URL whose scheme region may already hold a value (later values judged as if one came first); a / in a script after branches that disagree on division vs regex is refused.

text mode escapes nothing; expr mode returns a typed value.


8. Data declarations ​

8.1 Syntax and placement ​

jinja
{% data post    = blog.post(slug=request.params.slug) %}
{% data related = blog.related(post=post.id, limit=3) %}

Allowed only in a page template, a layout, or a module definition, before any output. Not in partials or macros — those receive data as arguments. A layout's and every placed module's declarations are aggregated with the page's.

8.2 Arguments ​

Each argument is one of: a literal; a request value the source declares for THAT argument (request.params.*, request.query.* — validated and mapped by the source, so a visitor chooses a window or a declared option, never a query: ?sort= fills sort_key, the pick among declared options, and is refused in sort, the raw ordering); a module field (module.limit, inside a module definition); a field of an earlier declaration's result (post.id); or a or b of those — the first that is set (handle=module.productId or request.params.handle).

8.3 Checked at save ​

The source exists; arguments match its schema; the declaration graph has no cycle and at most 2 levels of dependency; at most 10 declarations per page after aggregation; and the author holds the grants to publish what each source reads (today's bind gate, assertCanPublishObject). A body that reads a name nobody declared, set or imported is a save WARNING that names the {% data %} line to add — not an error: the name reads undefined (as any missing value does), and a template meant to be bound later (a collection page before its data object is picked) tests it with is defined.

8.4 Loaded before the render ​

Aggregated declarations are deduplicated by (source, arguments) — two modules showing the same list cost one query — and loaded level by level, each level in parallel. Each source call has a 1.5 s timeout and the whole page a 3 s budget. Results are cached per (source, arguments) with the source's TTL and invalidated by its domain events.

A required argument the request does not set — slug=request.params.slug on a URL without that param — makes the declaration none without a load: the page has no such item, which is not a failure.

8.5 When a source fails ​

Stale-if-error: a failed or timed-out call serves the last cached result for the same (source, arguments). Only when there is none does the name resolve to unavailable — distinct from an empty list, so a template can say so ({% if products is unavailable %}) instead of rendering "no products" while the database is down. A page rendered with any stale or unavailable data is not stored in the HTML cache.

8.6 Sources ​

A code registry (like capability manifests), one entry per source: argument schema, accepted request values, literal-only arguments, grant check, cache TTL/stale window, and the pure load.


9. Ambient scope ​

Always present, never declared: site, page, theme, request (path, params, query, locale), local_dt (the render's start time, HubL's name — the footer year), member (when the site has members), and — inside a module — module (its field values and id). The authoritative list and its trust rules stay in the website module card; this file does not restate it.


11. Not in the dialect — and what to write instead ​

ConstructWhyInstead
HubL data functions (hubdb_table_rows, blog_recent_posts, crm_objects, …)P2a {% data %} source
regex_replace, any regexP3replace / split
random, shuffle, clock without format/timezoneP6randomize client-side; format_datetime
{% autoescape %} / {% filter %} blocksP5 / P1|safe on the one value; apply the filter to the value
escape / e / forceescapeP5 — autoescape already did itnothing, or |safe
{% cycle %} / {% ifchanged %} tagsP1loop.cycle() / loop.changed()
{% with %}P1{% set %} inside the block you need
attr, xmlattr, pprint, urlize, wordwrapP1/P3 — attribute building belongs to the escaper, the rest is unused./[]; explicit markup
HubL filters: add multiply divide divisible cut bool format escapejson format_currency(_value) rootP1+ * / · divisibleby test · replace · the value itself · ~ · tojson · money/format_number · **
HubL filters: escape_html escape_attr escape_js escape_url escape_jinjava unescape_htmlP5 — output is escaped for its contextnothing (urlencode for a query value, {% raw %} for literal delimiters)
HubL: strtotime strtodate convert_rgb geo_distance render md5 ipaddr log, tests within string_containingP1/P2 — data dates are ISO already, colour maths is CSS's, templates compile at saveformat_date/plus_time · CSS color-mix() · a {% data %} source · {% include %} · in · containing
String/list methods ("x".upper(), s.split())P1the filter of the same name
Liquid: assign capture render case/when layout comment echo liquid incrementP1 — the dialect is Jinjaset · block set · include/macro · if/elif · extends · {# #} · {{ }} · — · namespace()
Liquid filters: upcase downcase strip size append/prepend plus/minus/times/divided_by/modulo where group_by uniq compact json url_encode strip_html date rawP1upper lower trim length ~ operators selectattr groupby unique reject("none") tojson urlencode striptags format_date/datetimeformat safe

Each of these fails at save with the "instead" column in the message.


12. Modes ​

ModeUsed byOutput
htmlwebsite pages/layouts/modules, email bodies, marketing rich bodies, PDF documentsstring, contextually escaped
textemail subjects, SMS/chat channel bodies, AI promptsstring, nothing escaped
exprautomation node config and conditionsone expression's typed value (not a string); statements are not allowed

A host may add filters whose semantics are its own — the website: money, t, image_url …; automation: date_add/date_subtract/date_diff, format_currency in major units, and re_extract, a regex filter that meets P3 because it compiles with RE2, linear in a subject capped at 8 KB.

Data sources available to a website ​

  • records.list(object*, filters, sort, sort_options, page_size, page, sort_key) — may read page=request.query.page, sort_key=request.query.sort
  • records.get(object*, key*, field, filters, title_field) — may read key=request.params.slug, key=request.params.id, key=request.params.handle
  • blog.list(limit, tag)
  • blog.post(slug*) — may read slug=request.params.slug, slug=request.params.handle
  • commerce.products(limit, category, q, collection, page) — may read q=request.query.q, collection=request.query.collection, page=request.query.page
  • commerce.product(handle*) — may read handle=request.params.handle, handle=request.params.slug, handle=request.params.id
  • commerce.collections()
  • commerce.nav()
  • menus.get(handle, id)
  • forms.get(id*)
  • pricing.plans()

(* marks a required argument.)