Skip to content

Latest commit

 

History

History
58 lines (38 loc) · 1.77 KB

templates.md

File metadata and controls

58 lines (38 loc) · 1.77 KB

Template engines

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

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}}

rustdocs (main)

Ructe

Ructe is a compile-time typed template system similar to askama, but using a build script instead of macros.

Tera

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}}

rustdocs (main)

Handlebars

Handlebars also offers runtime templating. Given the following file in examples/templates/hello.hbs,

{{#include ../../../handlebars/examples/templates/hello.hbs}}
{{#include ../../../handlebars/examples/handlebars.rs}}

rustdocs (main)