Interpolation
[expr] is Rat's one read mechanism. The same brackets work in text content, attribute values, CSS, and even inside other [expr]s. The expression grammar is small. It covers maths, equality, member access, function calls, and array and object lookups.
Read a value
Plain identifier read
[name] reads name from the nearest scope frame and renders it as a string. No quotes and no escaping needed.
> server
who: 'Ada'
> page
<p> Hello, [who]! Hello, Ada!
Inline expressions
Maths, comparisons, function calls
Any valid expression goes inside the brackets. Arithmetic, string concatenation with +, and calls to functions like len(...) all work.
> server
age: 36
items: ['apples', 'pears', 'figs']
> page
<p> Born around [2026 - age].
<p> You have [len(items)] items in the basket. Born around 1990.
You have 3 items in the basket.
Member access
person.first, items0
Objects and arrays use the same dot/bracket access as most languages. Reads chain through nested fields without extra syntax.
> server
person: {first: 'Grace', last: 'Hopper'}
items: ['apples', 'pears', 'figs']
> page
<p> [person.first] [person.last]
<p> First item: [items[0]] Grace Hopper
First item: apples
Attribute interpolation
Brackets work inside attr values too
Any attribute value accepts [expr]. Combine literals with expressions to build links, classes, or style hooks.
> server
slug: 'getting-started'
> page
<a href['/posts/[slug]']> Read post A literal open bracket
Escape with a backslash inside a string
Because [ opens an interpolation, a string literal that needs a real [ escapes it as \[. A bare [ inside a string raises unclosed [ in string. The closing ] and the brace and paren characters ({ } ( )) need no escaping.
> page array syntax: [1, 2, 3]
Resultarray syntax: [1, 2, 3]
See also HTML attributes · Reactivity · Functions