
Enter a search term above to see results...
Enter a search term above to see results...
The Abstract Syntax Tree (AST) is a representation of your template that is used by a rendering pipeline to generate your component.
When the TemplateCompiler
compiles a template string, it generates an AST. This intermediate representation serves several purposes:
The AST consists of various node types, each representing a specific element or control structure in the template. Below are the main types of nodes you’ll encounter in the AST:
Represents static HTML content.
{ type: 'html', html: '<div class="container">'}
Represents a dynamic expression to be evaluated.
{ type: 'expression', value: 'user.name', unsafeHTML: false}
Represents an if/else if/else control structure.
{ type: 'if', condition: 'user.isLoggedIn', content: [/* nested AST nodes */], branches: [ { type: 'else', content: [/* nested AST nodes */] } ]}
Represents a loop structure for iterating over arrays or objects, with optional handling for empty collections.
{ type: 'each', over: 'items', as: 'item', content: [/* nested AST nodes */]}
{ type: 'each', over: 'items', as: 'item', indexAs: 'i', content: [/* nested AST nodes */]}
{ type: 'each', over: 'items', as: 'item', content: [/* nested AST nodes for non-empty case */], else: { type: 'else', content: [/* nested AST nodes for empty case */] }}
Represents a nested template or partial.
{ type: 'template', name: 'partialName', data: { key1: 'value1', key2: 'value2' }}
Represents a reusable template snippet.
{ type: 'snippet', name: 'snippetName', content: [/* nested AST nodes */]}
Represents a slot for content projection in web components.
{ type: 'slot', name: 'header'}
Represents SVG content, which may require special handling during rendering.
{ type: 'svg', content: [/* nested AST nodes representing SVG content */]}
Semantic UI ships with a Lit rendering engine, but Semantic UI templates can hypothetically be used with any custom renderering engine that supports dynamic expressions.
For example, a basic renderer might:
By working with this AST structure, you can create highly optimized and flexible rendering systems that suit your specific needs while leveraging the powerful parsing capabilities of the Semantic UI Templating system.