On This Page
Templating
What is Templating
Templates provide a syntax for generating html that can be used to power your components. They allow for looping, conditionals, expressions, and a data context to make it easier to retrieve data when rendering web components.
Template Syntax
Templates all support either single or double bracket syntax and are whitespace insensitive. Use what style you and your team prefer.
Single Bracket
Double Bracket
Flexible Dialects - Compiling templates is inexpensive so supporting additional syntaxes comes at little cost. For people coming from a
jsx
orsvelte
background single bracket notation might feel more familiar. For those coming frommeteor
,rails
, orphp
using double brackets might be more at home. Both achieve the same results, but allow for developer and team preference.
Template Usage
Templates compile to an ast
that is used to create the Shadow DOM of web components. This makes sure that only the parts that need updating in your component are modified when reactive changes occur.
Components include a custom templating language built for web components. This language compiles to an Abstract Syntax Tree or AST
that is used to render your component and surgically update portions of the DOM when reactive data sources change.
For more information about how templates are used inside components see the dedicated section for component templates
Template Features
Expressions
Expressions allow values to be ouput and functions to be executed from the template’s data context.
Value Output
Function Calls
Complex Nested Expressions
Nested expressions
HTML Output
Conditionals
If / elseif / else
Loops
With intermediate value
With inner data context
With array index
Content Slots
Default Slot
Named Slot
Global Helpers
Built-in helpers
Subtemplates
Named Templates
Dynamic Template Support
Reactive Data Controls