Conditionals¶
Use conditionals to render sections conditionally based on context values.
Syntax
if subscribed:
<< Thanks for subscribing, ${name}! >>
else:
<< Please consider subscribing. >>
Rendered results
- When
subscribedis true andnameisDana:
Thanks for subscribing, Dana!
- When
subscribedis false or missing:
Please consider subscribing.
elif¶
Use elif to add additional branches without nesting:
if status == "premium":
<< Premium user >>
elif status == "standard":
<< Standard user >>
elif status == "trial":
<< Trial user >>
else:
<< Unknown status >>
Any number of elif branches can follow an if. An optional else branch at the end catches all remaining cases.
Notes
- Conditions evaluate truthiness: missing, false, empty, or null values are treated as false.
- You can reference nested values with dotted paths, e.g.
user.active. elifis syntactic sugar for a nestedifin the false branch; no additional AST nodes are needed.
Tip: Use margarita metadata or a dry render to ensure required context keys are present before running in production.