Rat docs

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 but covers maths, equality, member access, function calls, and array / object lookups.

Read a value

Plain identifier read

[name] reads name from the nearest scope frame and renders its stringified form. No quotes, no escaping ceremony.

> server
who: 'Ada'

> page
<p> Hello, [who]!
Result

Hello, Ada!

Inline expressions

Maths, comparisons, function calls

Anything that's a valid expression goes inside the brackets. Arithmetic, string concatenation with +, and calls to functions like len(...) all compose.

> server
age: 36
items: ['apples', 'pears', 'figs']

> page
<p> Born around [2026 - age].
<p> You have [len(items)] items in the basket.
Result

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]]
Result

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 without templating gymnastics.

> server
slug: 'getting-started'

> page
<a href['/posts/[slug]']> Read post

Next: HTML attributes — bracket-attr syntax, the snake_case to kebab-case rule, boolean flags, and interpolated attribute values.