A lightweight Jinja2-inspired template engine for the SunWeb framework.
You should not depend on this crate directly — use [sunweb] with the
templating feature instead, which re-exports everything from here.
Template Syntax
| Syntax | Description |
|---|---|
{{ name }} |
Inserts a variable (HTML-escaped by default) |
{{ name | safe }} |
Inserts a variable without escaping |
{{ name | upper }} |
Applies a filter |
{{ name | default("x") }} |
Filter with argument |
{# comment #} |
Comment — stripped from output |
{% if cond %} ... {% endif %} |
Conditional block |
{% if cond %} ... {% else %} ... {% endif %} |
If/else |
{% if cond %} ... {% elif cond2 %} ... {% endif %} |
If/elif/else |
{% for x in list %} ... {% endfor %} |
Loop over a list |
{% for x in list %} ... {% else %} ... {% endfor %} |
Loop with empty fallback |
{{ loop.index }} |
1-based loop index (inside for) |
{{ loop.index0 }} |
0-based loop index (inside for) |
{{ loop.first }} |
"true" on first iteration |
{{ loop.last }} |
"true" on last iteration |
{{ loop.length }} |
Total number of items |
{% set x = value %} |
Set a variable in current scope |
{% raw %} ... {% endraw %} |
Output block literally, no processing |
{%- tag -%} |
Strip whitespace around a tag |
Filters
upper, lower, capitalize, trim, length, wordcount,
reverse, escape, safe, default("fallback"),
replace("a","b"), truncate(n), join("-"), abs, round
Filters can be chained: {{ name | upper | truncate(10) }}
Conditions
Conditions support ==, !=, >, <, >=, <=, and, or, not.