Basics
Parsing from Strings
using IwaiEngine
template = IwaiEngine.parse("Hello {{ name }}!")
template((name = "Iwai",))"Hello Iwai!"Loading from Files
IwaiEngine.load caches compiled templates by file path and mtime.
template = IwaiEngine.load("views/index.iwai")
html = template((title = "Home",))Context Values
Render contexts are passed as NamedTuples.
using IwaiEngine
template = IwaiEngine.parse("{{ title }} / {{ count }}")
template((title = "Todos", count = 3))"Todos / 3"Filters
using IwaiEngine
template = IwaiEngine.parse("""
{{ name|upper }}
{{ missing|default("fallback") }}
{{ values|join(", ") }}
""")
template((name = "iwai", values = [1, 2, 3]))"IWAI\nfallback\n1, 2, 3\n"Autoescape
Autoescape is enabled by default for {{ ... }} expressions.
using IwaiEngine
template = IwaiEngine.parse("""
{{ html }}
{{ html|safe }}
{% autoescape false %}
{{ html }}
{% end %}
""")
template((html = "<b>x</b>",))"<b>x</b>\n<b>x</b>\n\n<b>x</b>\n\n"