Guards and loops
Rat has no if/else keyword. Conditions are written as parenthesized guards followed by an action — (cond) action. Adjacent guards form a first-match chain; (else) closes one. Loops use [item] in coll on the body line.
One guard, one action
No else needed when not used
A lone guard runs its action only when the condition is true and falls through otherwise. Use it for inline gates: render an admin link only when authed, show an error only when one exists.
> server
score: 78
> page
<p> score: [score]
(score >= 50)
<p class['pass']> passing score: 78
passing
First-match chain
Sibling guards short-circuit at the first hit
Stacked guards at the same indent form a chain — only the first matching branch runs. Use (else) as the final catch-all when one is required.
> page
(score >= 90)
<p> excellent
(score >= 50)
<p> passing
(else)
<p> needs work Loop with in coll
Iterate over arrays
Place the binder on the body line just like a tag. The framework rebinds the loop variable on each pass, so any handlers attached to the elements capture the right value. Empty collections render nothing.
> server
items: ['apples', 'pears', 'figs']
> page
<ul>
[item] in items
<li> [item] - apples
- pears
- figs
Guards inside a loop
Compose freely
Guards and loops nest in either direction. Filter the rendered output inline rather than precomputing a separate array.
> page
<ul>
[item] in items
(len(item) >= 5)
<li> [item] - apples
- pears
Next: head into Pages — how files under pages/ become routes.