Client templates (QWeb for the web client)
Status: implemented (erp-ui-compiler, trusted mode, base directives, rejection table, IR, codegen, coarse root source maps, limits, injection protection, native/WASM identity).
Implements: ADR 0030 (Elang), design notes docs/design/m4-ui0-compiler.md (docs/design/m4-ui0-compiler.md, not part of the published documentation) and docs/design/m4-ui2.md (docs/design/m4-ui2.md, not part of the published documentation).
Specs: docs/specs/ui/templates.md (SPEC-UI-003, 004, 009, 010, 015, 091, 096, 098, 100, 101, 102, 105, 106, 109, 110 whole; 007, 011, 013, 018, 024, 030, 092, 097 compile-time half).
See declared UI assets for the client manifest and publication APIs.
An addon’s client templates live in static/src/**/*.xml, written in OWL’s QWeb dialect as in Odoo. ERPForAll
does not ship them to the browser as XML: at install and upgrade they are compiled on the server into one ES
module per template, so the browser never parses a template or evaluates code built from strings. A mistake in a
template is reported when the addon is installed. Unique original nodes and inheritance operations carry
their addon, file, line, column, template and applicable spec ordinal. When changed attributes prevent a
verified literal attribution, the diagnostic clears the location and lists explicit source candidates;
it does not attribute an extending addon’s expression to the root addon. A declaration has spec n/a.
1. Files
Section titled “1. Files”A template file holds templates under a root <templates> (Odoo also accepts <template> and <odoo>, and so do
we; any other root element is itself the file’s only template). Under the root: template elements, whitespace and
comments; text there is an error. DTDs, processing instructions and namespaces are refused, except xml:space on
the root and the SVG namespace on <svg>.
<templates xml:space="preserve"> <t t-name="my_addon.Counter"> <button class="btn" t-on-click="() => this.state.count++"> Clicked <t t-out="this.state.count"/> times </button> </t></templates>Template names use [A-Za-z0-9_.:-], up to 256 bytes, and are unique in the whole set (all installed addons).
2. Names in expressions: this. or a template local
Section titled “2. Names in expressions: this. or a template local”Expressions are JavaScript expressions with QWeb’s word operators (and, or, gt, gte, lt, lte). Every
name must be one of:
thisand its members: the component (this.props.record,this.state.open,this.onClick);- a template local: a
t-foreachvariable (row,row_index,row_value,row_first,row_last), at-setname after its declaration, thet-slot-scopeobject, an arrow-function parameter; - an allowed global:
Math,JSON,Number,String,Boolean,Array,Object,Date,RegExp,NaN,Infinity,undefined(andconsolein dev builds).luxonis not a template global: Odoo templates never read it, and a component that formats dates exposes the value or a method.
A bare name that is none of these is an install error (unknown identifier 'label' … use this.label for a component member). window, document and other browser globals are not available in templates: expose what you
need from the component.
A template called with t-call may read its caller’s locals; the compiler checks every call site statically. Subtemplate contexts are passed via t-call-context, caller body content is accessed via 0 (<t t-out="0"/>), and recursive calls are limited to 64 levels.
Refused in expressions, each with a reason: function/class expressions, new, await, yield, comma
sequences, eval, instanceof, delete, void, tagged templates, regular expressions, getters and methods in
object literals, a __proto__ key, comments, and any assignment or update evaluated while rendering. Assignments
are allowed in t-on-* handlers and inside arrow functions.
3. Directives
Section titled “3. Directives”| Directive | Notes |
|---|---|
t-if / t-elif / t-else | OWL’s structural rules and messages (branch order, no text between branches, one per node) |
t-foreach + t-as + t-key | t-key is required |
t-out (t-esc deprecated, a warning) | escaped text; markup(…) values as HTML; a body is the fallback for null/undefined |
t-att-<name>, t-attf-<name>, t-att | class/style merge with the static value; IDL properties (value, checked, …) are set as properties |
t-on-<event>[.stop.prevent.self.capture.synthetic.passive] | a method reference or an arrow function |
Components <MyComp prop="expr" label.translate="Text" cb.bind="this.m"/> | props are expressions; an empty value is undefined |
t-set-slot, t-slot / t-call-slot, t-slot-scope | named and default slots |
t-set, t-call, t-ref, t-model, t-portal, t-tag, t-component | base directives compiled into fine-grained reactive DOM operations and helper ABI bindings |
t-custom-<name> | the name must be registered by an installed addon (click and portal by web); runs in a later delivery |
t-translation="off", t-translation-context | Source compilation validates declarations; explicit localized compiler APIs are described below. Assembly integration is planned. |
t-debug, t-log | stripped from production builds |
Refused on purpose: t-raw (removed in OWL 2; use t-out with markup), t-call-block (OWL-internal), and
t-valuef, which Odoo’s OWL silently ignores (BUG-063 in docs/compare/odoo-bugs.md: write t-value="'…'"). Any
other t-* attribute is Unknown QWeb directive.
A plain attribute on a <t> node is an error: a <t> renders no element to carry it, so class or style there
would be lost (Odoo’s OWL drops it without a word, BUG-065). Put it on an element. The markers Odoo’s templates carry
on <t> (owl, name, id, data-id) are accepted with a warning and ignored.
Warnings (the template still compiles, the output is what OWL renders): the <t> markers above, t-esc
(deprecated, use t-out), and t-set-slot outside a component, whose content renders in place.
Markup the browser’s HTML parser would restructure (a <tr> directly in a <table>, a <div> or <li> inside a
<p>, text directly in a <select>, an element inside an <option>, a table cell next to a non-table element at the
top of a template or branch) is an error, because the compiled template is cloned from HTML: write the <tbody>, or
move the element. HTML element names are lowercase (<noScript> is refused) and come from the HTML standard’s element list or are
custom elements with a - in the name (<my-widget>); elements the parser would drop, rename or treat specially in
a template (<body>, <html>, <head>, <frame>, <image>, <param>, <nobr>, <rt>, <rp>, <object>,
<marquee>, <base>, …) are refused with the reason. Inside <svg>, only the common SVG
shape, text, gradient and grouping elements are accepted (the error lists them); <foreignObject>, <style>,
<script>, <a> and animation elements in SVG, and <math>, are refused.
4. Inheritance
Section titled “4. Inheritance”Template inheritance runs on the same engine as server views (erp-views, views.md): t-inherit="parent"
with t-inherit-mode="primary" (the default: a new template built on the parent, with its own t-name) or
"extension" (modifies the parent in place, no t-name). Extensions apply in install order (addon dependency order,
then file order, then position in the file); a primary child sees every extension of its parent, also those
installed after it. A missing parent, an unknown mode or an XPath outside the engine’s subset (ADR 0027: no ..,
following-sibling:: or contains()) is an install error naming the template.
A primary child keeps the parent’s combined content, changes the root tag to the child’s tag,
and overlays the child’s root attributes (including its own t-name), except t-inherit and
t-inherit-mode. Inheritance specs run before that child’s root overlay; a later extension or
primary descendant can select the merged root. Ordinary server-view primary inheritance keeps
its existing behavior; the template adapter opts into root merging explicitly.
Use t-anchor="row.actions" on an element to declare a stable extension target, then
<anchor name="row.actions" position="after"><i/></anchor> in an inheriting template.
The shorthand uses the same positions and limits as XPath, including nested moves; it becomes
an XPath selecting the unique t-anchor. Names contain 1–128 bytes from [a-z0-9_.@-].
A missing name, unknown shorthand attribute, invalid operation or duplicate anchor fails
compilation. Anchor uniqueness is local to one complete template, including all inherited
nodes; separate templates can reuse a name. A combined-duplicate diagnostic identifies both
node tags and their source entries, and points to the entry that introduced the duplicate.
Development output includes data-t-anchor; production output strips it.
In template position="replace" operations, an exact $0 text node is replaced at its
position by a copy of the target. Thus <section>$0<i/></section> keeps the target before
<i/>; the target’s following text stays with its original parent rather than being copied.
Copies still occur after moves, retaining ADR 0027’s duplicate-move prevention. This template
policy is explicitly selected by the adapter; the server-view engine’s existing append policy
is unchanged.
UI3 base coverage and evidence boundary
Section titled “UI3 base coverage and evidence boundary”This matrix describes implemented behavior and executable test coverage, not a blanket parity verdict.
The numbered behavior and its historical evidence are in
the template specification (docs/specs/ui/templates.md). In this authoring task, the local Community
reference read for primary-root and $0 behavior was commit
98f53af0148cd4801de7c1342657573ddd005dac (templates.js:63–72,
template_inheritance.js:268–278). It was not refreshed in this subtask; this does not replace the
specification’s historical pins or establish current upstream parity.
| Case | Implemented behavior / test pointers | Partial or remaining evidence |
|---|---|---|
| SPEC-UI-018 | Primary/extension roles and invalid inherit mode: compiler inherit_modes | Compiler role coverage; whole browser case is not claimed |
| SPEC-UI-019 | Root tag/attribute merge and descendant selectors: primary_root_tag_and_attributes_are_merged, primary_root_merge_is_visible_to_grandchildren; engine opt-in leaves server views unchanged | Final rendered-source evidence is recorded separately |
| SPEC-UI-020 | Extensions change the parent without adding a named template: inherit_modes | Compiler output coverage; final browser case is separate |
| SPEC-UI-021 | Inside/before/after use the existing bounded engine; inside and anchor-after run through compiler tests | Complete operation/render matrix is broader than these compiler fixtures |
| SPEC-UI-022 | Outer $0 copies occupy their text position; following text and ordinary server behavior are isolated: inherited_replace_wraps_the_target_with_dollar_zero, engine template_dollar_zero_keeps_its_text_position_and_server_views_keep_append | Inner replace and moves retain engine tests; no whole-case browser parity claim |
| SPEC-UI-023 | Attribute operations use the engine; joined t-if compiles: inherited_condition_attributes_compile_as_conjunction | Full token/separator and rendered condition combinations remain separate evidence |
| SPEC-UI-024 | Missing parents fail at assembly and retain declaration metadata: missing_parent_fails_at_assembly, declaration_errors_keep_template_and_source_metadata | The typed compiler kind is MissingTemplate; no browser-runtime failure is substituted for install refusal |
| SPEC-UI-025 | A primary child sees later parent extensions: primary_child_sees_later_addon_extensions; adapter synthetic_ids_give_load_order fixes applied IDs | Browser rendering and final exact-source execution are recorded separately |
| SPEC-UI-026 | Anchor shorthand, validation, per-template uniqueness, duplicate origins and dev/prod metadata: compiler anchor tests | Locator lint and anchor API diff are UI3-DONE; generated-range source maps remain partial |
| SPEC-UI-103 | Unmatched operations preserve the leaf error, original source location and BFS spec ordinal: unmatched_xpath_reports_the_offending_spec_source, engine ui_spec_errors_retain_operation_context_and_underlying_kind | XPath remains the explicit ADR 0027 subset; non-element target parity is not claimed |
| SPEC-UI-104 | Invalid positions/modes fail loudly; compiler shorthand and existing engine error tests cover these paths | Final combined-suite execution is required; no whole-case UI parity claim |
| SPEC-UI-110 | Invalid extensions fail the set and dependent templates; declaration and combined-expression diagnostics identify source/spec where proven | Transactional previous-bundle preservation is integration evidence, not established by a compiler unit test |
| SPEC-UI-113 | Compiler outputs are deterministic and authority is outside this pure crate | Two-process serving, compatible generation and node loss require the slice’s integration receipts |
Source-node ordinals survive imports, moves and copies. The diagnostic mapper checks unchanged original
tag/attributes before assigning a literal source. Mutated nodes use at most 16 visible candidates with
an explicit omitted count. Original position tables are computed in one UTF-8 pass per file. Their index,
combined mapping rows and diagnostic labels have a cumulative portable charged-byte admission budget of
min(input_bytes, 64 MiB); overflow is an explicit inheritance-provenance storage refusal. This is a
safety limit, not measured allocation or performance acceptance.
Generated JavaScript source maps currently attribute generated lines to the root file at line 1. They are coarse maps: the precise diagnostic mapping above does not establish per-generated-range inherited source-map attribution. Full generated-range maps remain partial and must not be used as proof of an extending addon’s precise generated-code location.
5. Limits
Section titled “5. Limits”Per file: 4 MiB, 200 000 XML nodes, 64 levels of element nesting (Odoo’s deepest client template has 19), 256
attributes per element. Per expression: 4096 bytes, 64 levels of bracket nesting. Per template: 4096 locals,
512 reactive effects, 64 recursive t-call depth levels. Per set: 20 000 files and 128 MiB of input (both checked
before any file is parsed), 20 000 templates; per generated module 2 MiB, all modules 128 MiB. At most 256 custom
directives (MAX_CUSTOM_DIRECTIVES). A limit hit is an error naming the limit, its maximum and the actual value.
6. Running the compiler yourself
Section titled “6. Running the compiler yourself”erp-ui-compile reads a framed request on stdin and writes the canonical result on stdout; its wasm32-wasip1
build gives byte-identical output and the same exit status (the CI step ui-compiler-wasm-identity proves it).
It exits 0 when the result has no error, 1 when it carries errors (the result is still on stdout), 2 for a malformed
or oversized request. The framing (tagged records: operation, mode, custom directives, lowered limits, files) is
documented in the erp-ui-compiler-cli crate. From Rust:
use erp_ui_compiler::{ AddonName, BuildMode, CompileOptions, TemplatePath, TemplateSet, TemplateSource, analyze, compile,};
let mut set = TemplateSet::new();set.push(TemplateSource::addon_file( AddonName::new("my_addon")?, TemplatePath::new("static/src/counter.xml")?, "<templates><t t-name=\"my_addon.Counter\"><b t-out=\"this.state.count\"/></t></templates>",));let options = CompileOptions::new(BuildMode::Prod).with_custom_directive("click")?;let analysis = analyze(&set, &options); // every template's verdict and diagnostics, never failsassert!(analysis.is_clean());let compiled = compile(&set, &options).map_err(|e| format!("{:?}", e.errors()))?;assert_eq!(compiled.modules()[0].name().as_str(), "my_addon.Counter");# Ok::<(), Box<dyn std::error::Error>>(())Compiler localization and term extraction
Section titled “Compiler localization and term extraction”ADR 0129 supplies two explicit pure library operations through the native SDK’s
ui_compiler facade. Normal compile still emits source literals and its existing
translation-skipped diagnostic. compile_localized consumes a validated immutable
catalogue; extract_translations uses the same literal selection rules and returns
sorted module/source groups with original source occurrences. These library APIs
do not install a language or select a different served bundle.
use erp_ui_compiler::{ AddonName, BuildMode, CompileOptions, TemplatePath, TemplateSet, TemplateSource, TranslationCatalogue, compile_localized, extract_translations,};// Native addon hosts may use the equivalent erp_sdk::ui_compiler facade.let mut templates = TemplateSet::new();templates.push(TemplateSource::addon_file( AddonName::new("my_addon")?, TemplatePath::new("static/src/hello.xml")?, r#"<templates><t t-name="my_addon.Hello"><p>Hello</p></t></templates>"#,));let catalogue = TranslationCatalogue::new("fr_FR")? .with_term(AddonName::new("my_addon")?, "Hello", "Bonjour")?;let options = CompileOptions::new(BuildMode::Prod);let localized = compile_localized(&templates, &options, &catalogue)?;let terms = extract_translations(&templates, &options)?;assert!(localized.modules()[0].code().contains("Bonjour"));assert_eq!(terms.terms()[0].source(), "Hello");# Ok::<(), Box<dyn std::error::Error>>(())Static text uses XML whitespace at its lookup boundaries and preserves surrounding
whitespace in the emitted text. Nonbreaking spaces remain significant. DOM
translation covers alt, aria-label, aria-placeholder, aria-roledescription,
aria-valuetext, label, placeholder, title and data-tooltip. Component and
call properties are expressions unless declared with .translate; those
expressions are never rewritten as translated text. Lexical
t-translation-context="my_addon" selects a module, and
t-translation="off" excludes a subtree. A DOM attribute may select its own
module with t-translation-context-title="my_addon" (and the corresponding
allowlisted attribute names).
Lookup is module, global catalogue, then source text. A catalogue language is an identity, not proof that the database has installed it. Wrong language syntax, conflicting entries and size/count limits return typed errors. Values remain literal data through HTML/JavaScript escaping; never treat catalogue values as executable templates. Ambiguous inherited source ownership is an error rather than attribution to the root addon.
Both APIs validate the untranslated source through semantic and HTML/codegen admission before selection/substitution. Empty or blank translations cannot hide source errors; extraction also rejects source constructs whose codegen is deferred. Localized output still obeys its own compiler limits. Ordinary blank translations remain valid where the source structure is valid.
Original element identity cannot establish the owner of text merged by inheritance.
When an applied operation has nonblank raw text/tails, replacement, move or $0,
A conservatively refuses selected text throughout that combined template with an
Inheritance diagnostic that says the case is not integrated yet and lists the candidate sources.
This may include unchanged text in the same template. Element-only insertions
without raw operation text/tails remain supported; ordinary source compilation is
unchanged. Do not use these APIs to claim complete inheritance/localization parity.
Selected inherited attributes also refuse after an applied attribute mutation,
even if its final value equals the original or is restored by a later extension.
The conservative check covers DOM attributes and literal .translate properties,
and may include untouched attributes elsewhere in that combined template.
Original element identity alone does not prove an unwritten attribute.
Ordinary callee and slot literals retain declaration ownership. Caller-context or
translation-off propagation requiring a separately compiled callee specialization
is explicitly refused until that integration is delivered. The broad translation case
therefore remains partial. Context-preserving PO/POT and erp ui extract are
planned; language-specific publication is planned too. Localized compilation must not enter assembly before its
key carries catalogue content, as required by ADR 0129.
Catalogue source keys and values reject NUL bytes with TranslationError::Nul,
which identifies source or value and the first UTF-8 byte offset. HTML parsing
can remove or replace NUL, so the catalogue rejects it before duplicate lookup or
storage rather than silently changing the literal. Both module and global term
builders enforce this admission; ordinary Unicode and blank translations retain
their documented behavior.