There are currently three template engines for trillium. Although they are in no way mutually exclusive, most applications will want at most one of these.
Askama is a jinja-based template engine that preprocesses templates at compile time, resulting in efficient and type-safe templates that are compiled into the application binary. Here's how it looks:
Given the following file in (cargo root)/templates/examples/hello.html
,
{{#include ../../../askama/templates/examples/hello.html}}
{{#include ../../../askama/examples/askama.rs}}
Ructe is a compile-time typed template system similar to askama, but using a build script instead of macros.
- crate: https://crates.io/crates/trillium-ructe
- repository: https://github.com/prabirshrestha/trillium-ructe
- docs: https://docs.rs/trillium-ructe/latest/trillium_ructe/
Tera offers runtime templating. Trillium's tera integration provides an interface very similar to phoenix
or rails
, with the notion of assigns
being set on the conn prior to render.
Given the following file in the same directory as main.rs (examples in this case),
{{#include ../../../tera/examples/hello.html}}
{{#include ../../../tera/examples/tera.rs}}
Handlebars also offers runtime templating. Given the following file in examples/templates/hello.hbs
,
{{#include ../../../handlebars/examples/handlebars.rs}}