larztemplate
A tiny template engine.
Every real app builds strings from data - web pages, emails, config. Rather than messy concatenation you use a template. larztemplate is a small but genuine engine - {{ variables }}, {% for %} loops and {% if %} branches - to generate HTML and text cleanly, and to see how templating works.
larzscript pkg install template
What you get
- {{ variables }} with dotted access
- {% for %} and {% if/else %}
- Optional HTML escaping
- A readable parser + renderer
Try it
import "template" as template
let t = "Hi {{user.name}}!\n{% for x in items %}- {{x}}\n{% endfor %}{% if vip %}VIP!{% else %}Regular{% endif %}"
print(template.render(t, {"user": {"name": "Sam"}, "items": ["a", "b"], "vip": true}))
print(template.render("{{name}}", {"name": "<b>"}, true))Output
Hi Sam! - a - b VIP! <b>
Why it's in the Larz Stack
larztemplate is a real Larzscript package (larzscript pkg install template) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.