Syntax Reference
This is the complete reference for the Trellis template language. It documents
every tl:* attribute the engine ships with, the <tl:block> virtual element,
and every expression form you can write inside an attribute.
If you are new to Trellis, read Getting Started first, then come back here to look things up.
Expression language
The value of nearly every tl:* attribute is an expression. Learn the
expression syntax once and it applies everywhere.
- Expressions – variables
${...}, selection*{...}, URLs@{...}, messages#{...}, literals, arithmetic, ternary, Elvis, comparisons, boolean logic, filters, utility objects, and the no-op.
Attributes by group
- Text –
tl:text,tl:utext. - Conditionals –
tl:if,tl:unless,tl:switch,tl:case. - Iteration –
tl:eachand its status variables. - Attributes –
tl:attr,tl:href,tl:src,tl:value,tl:class,tl:id,tl:classappend,tl:styleappend,tl:attrs. - Fragments –
tl:fragment,tl:insert,tl:replace, and rendering a fragment as a response. - Composition –
tl:slotcontent slots,tl:attrsspreading and the...restfragment parameter, for building components from fragments. - Template inheritance –
tl:extends,tl:define. - Local variables & selection –
tl:with,tl:object. - Inline processing –
tl:inline. - Output control –
tl:removeand the<tl:block>virtual element. - Internationalization –
#{...}message expressions.
Processing order
When several attributes appear on one element, the engine applies them in a fixed priority order, highest first:
tl:with– bind local variablestl:object– set the selection contexttl:if/tl:unless– conditionalstl:switch/tl:case– multi-branch conditionalstl:each– iterationtl:insert/tl:replace– fragment inclusiontl:text/tl:utext– contenttl:attrand the attribute shorthands – attribute mutation. Within this grouptl:attrs(spread) runs first, so the other attribute directives override its entries.
tl:slot is not a processing step: it is resolved while a fragment is included
(step 6) and holds no place in this order.
Understanding this order explains, for example, why tl:if on the same element
as tl:each is evaluated before the loop runs.
-
Expressions
Almost every tl:* attribute takes an expression as its value. This page is the complete reference for the expression language. Learn it once and it applies in…
-
Text
Two attributes replace an element's body with a value: tl:text escapes the result, and tl:utext inserts it as raw HTML.
-
Conditionals
Trellis has two conditional mechanisms: tl:if / tl:unless for a single boolean test, and tl:switch / tl:case for multi-branch selection.
-
Iteration
tl:each repeats an element once per item in a collection.
-
Attributes
Trellis can set any HTML attribute from an expression. There is one generic attribute, tl:attr, plus convenient shorthands for the most common cases.
-
Fragments
Fragments are named, reusable pieces of a template. They are the foundation of Trellis's HTMX-first design: the same fragment renders inside a full page…
-
Composition
A component in Trellis is a fragment that accepts parameters, content and extra attributes from its caller. Three primitives provide that, with no new elements…
-
Template Inheritance
Template inheritance lets a page build on a shared layout, overriding named blocks. It is the layout-composition counterpart to fragments.
-
Local Variables & Selection
Two attributes shape the data available to an element and its children: tl:with binds named local variables, and tl:object sets a selection context for *{...}…
-
Inline Processing
tl:inline enables inline expression syntax inside an element's text content, so you can interpolate values without wrapping every one in its own…
-
Output Control
These two features control what actually reaches the output HTML: tl:remove strips elements or their tags, and <tl:block> groups content without emitting…
-
Internationalization
Trellis supports internationalized messages through #{...} message expressions backed by a MessageSource.