Module tera
Text template engine based on Jinja2/Django.
tera is a template engine inspired by Jinja2 and the Django template language.
It compiles templates to an internal representation and renders them
with a Context holding the variables.
Templates support inheritance, includes, for loops, conditionals,
filters, and custom functions.
The main entry point is the Tera struct, which loads and caches templates.
For one-off rendering without managing a template collection,
Tera::one_off renders a template string directly.
Examples
Rendering a template from a string:
use ;
let mut tera = default;
tera.add_raw_template.unwrap;
let mut ctx = new;
ctx.insert;
let output = tera.render.unwrap;
assert_eq!;
Using loops and conditionals:
use ;
let template = "{% for item in items %}{% if item.active %}{{ item.label }}, {% endif %}{% endfor %}";
let mut tera = default;
tera.add_raw_template.unwrap;
let mut ctx = new;
ctx.insert;
let output = tera.render.unwrap;
assert_eq!;
Quick one-off rendering without creating a Tera instance:
use ;
let mut ctx = new;
ctx.insert;
let output = one_off.unwrap;
assert_eq!;
Modules
- helpers Re-export some helper fns useful to write filters/fns/tests
Macros
- try_get_value Helper macro to get real values out of Value while retaining proper errors in filters