Using the template compiler
The template compiler is used by Aurelia under the hood to process templates and provides hooks and APIs allowing you intercept and modify how this behavior works in your applications.
Hooks
With VanillaJS
import Aurelia, { TemplateCompilerHooks } from 'aurelia';
Aurelia
.register(TemplateCompilerHooks.define(class {
compiling(template: HTMLElement) {
template.querySelector('table')?.setAttribute(someAttribute, someValue);
}
}));With decorator
import Aurelia, { templateCompilerHooks } from 'aurelia';
@templateCompilerHooks
class MyTableHook1 {
compiling(template) {...}
}
// paren ok too
@templateCompilerHooks()
class MyTableHook1 {
compiling(template) {...}
}
Aurelia.register(MyTableHook1);Supported hooks
Hooks invocation order
Compilation Behavior
Scenarios
Feature Flagging in Templates
Auto-Generating Form Field IDs for Label Association
Automatic ARIA Role Assignment
Content Security Policy (CSP) Compliance
Lazy Loading Image Optimization
Dynamic Theme Class Injection
Node APIs used
Last updated
Was this helpful?