Askama

Askama implements a template rendering engine based on Jinja.
It generates Rust code from your templates at compile time
based on a user-defined struct to hold the template's context.
See below for an example, or read the documentation.

"Pretty exciting. I would love to use this already." --
Armin Ronacher, creator of Jinja

All feedback welcome. Feel free to file bugs, requests for documentation and
any other feedback to the issue tracker or tweet me.
Many thanks to David Tolnay for his support in improving Askama.

Askama was created by and is maintained by Dirkjan Ochtman. If you are in a
position to support ongoing maintenance and further development or use it
in a for-profit context, please consider supporting my open source work on
Patreon.

How to get started

Because Askama will generate Rust code from your template files,
the crate will need to be recompiled when your templates change.
This is supported by adding a build script, build.rs, to your crate.
It needs askama as a build dependency:

externcrate askama;fnmain(){askama::rerun_if_templates_changed();}

Now create a directory called templates in your crate root.
In it, create a file called hello.html, containing the following:

Hello,{{ name }}!

In any Rust file inside your crate, add the following:

externcrate askama;// for the Template trait and custom derive macrouseaskama::Template;// bring trait in scope#[derive(Template)]// this will generate the code...#[template(path ="hello.html")]// using the template in this path, relative// to the templates dir in the crate rootstructHelloTemplate<'a>{// the name of the struct can be anythingname:&'astr, // the field name should match the variable name// in your template}fnmain(){let hello = HelloTemplate { name:"world"};// instantiate your structprintln!("{}", hello.render().unwrap());// then render it.}