Skip to content

Latest commit

 

History

History
96 lines (73 loc) · 3.68 KB

File metadata and controls

96 lines (73 loc) · 3.68 KB

Expressions

Any {{ ... }} tag accepts a small, sandboxed JavaScript-like expression. It can read values, provide fallbacks, compare, and do light math - but it can never call functions or run arbitrary code.

For the tags that host these expressions, see Syntax.

Table of Contents

Reading Values

A dotted path reads nested values. Missing data anywhere along the path resolves to undefined instead of throwing.

{{ user.profile.name }}
{{ user?.profile?.name ?? 'Guest' }}

Both . and ?. are null-safe, so a deep lookup never crashes the render.

Literals

{{ 42 }}
{{ 3.14 }}
{{ 1e3 }}
{{ 'single' }}
{{ "double" }}
{{ true }} {{ false }} {{ null }} {{ undefined }}

Numbers may be integers, decimals, or use exponents (2.5, 1e3, 6.02e23).

Strings and Escapes

Strings use 'single' or "double" quotes and understand the following escape sequences:

Escape Result
\n newline
\t tab
\r carriage return
\b backspace
\f form feed
\v vertical tab
\0 null character
\\ backslash
\" double quote
\' single quote
\/ forward slash
\xNN hex code point
\uNNNN Unicode code point
\u{...} Unicode code point (any length)
{{ 'line1\nline2' }}
{{ 'tab\there' }}
{{ '\u{1F600}' }}

Operator Reference

Listed from lowest precedence (top) to highest (bottom). Anything not on this list is rejected by the parser on purpose.

Group Operators Example
Ternary ? : {{ ok ? 'yes' : 'no' }}
Nullish ?? {{ name ?? 'Guest' }}
Logical OR || {{ a || b }}
Logical AND && {{ a && b }}
Equality === !== == != {{ role === 'admin' }}
Relational > < >= <= {{ age >= 18 }}
Additive + - {{ a + b }}
Multiplicative * / % {{ total % 2 }}
Unary ! + - {{ !done }}
Member . ?. {{ user?.profile.name }}
Grouping ( ) {{ (a + b) * c }}

Note

Expression nesting is capped at 64 levels. Deeper nesting throws a SyntaxError to stop pathological input.

What Is Not Allowed

DVE stays small so a template can never execute arbitrary code:

  • No function or method calls - {{ items.map(...) }}
  • No array/bracket indexing - {{ items[0] }}
  • No assignment or variable declarations
  • No regular expressions or arbitrary JavaScript

Anything that needs real logic belongs in your handler: compute the finished value there and pass it into the template via data.