Web · real, tested code

Render a Template in Larzscript

Fill a string template with dotted variables and a loop - no framework needed for a page, an email body, or a report.

template supports {{dotted.var}} substitution and a for/if pass (Mustache-lite or Jinja-style syntax, your pick), with optional HTML escaping - deliberately single-pass and non-nesting, a small subset rather than a full engine.

larzscript pkg install template

Code

import "template" as template

let t = "Hi {{user.name}}!\n{% for x in items %}- {{x}}\n{% endfor %}"
print(template.render(t, {"user": {"name": "Sam"}, "items": ["bread", "milk"]}))
Output
Hi Sam!
- bread
- milk