Expand description
Stilts is a rust-centric type safe template engine. It allows the users to create templates with arbitrary rust code within them, with a Jinja-like syntax. For more in depth documentation on the language check out the book.
It works using a derive macro that outputs template rendering code for the rust compiler to type check.
§Example
By default stilts looks for templates in the $CARGO_MANIFEST_DIR/templates
directory
this setting can be changed in the configuration.
Defining a template:
use stilts::Template;
#[derive(Template)]
#[stilts(path = "example.html")]
struct MyExample {
value: String,
}
Using said template:
let my_template = MyExample {
value: "Hello, World".to_string(),
};
let s: String = my_template.render().unwrap();
§Configuration
Configuration in stilts is done within your projects Cargo.toml this was done to reduce the need for seperate configuration file inside your project workspace. You can set the directory stilts searches for templates from, whether it will trim whitespace, the identifier of the writer that the generated code will use, and add/override custom escape formats. There is more in depth documentation here in the book.
§Example
These are the default values for all current configuration options
[package.metadata.stilts]
template_dir = "$CARGO_MANIFEST_DIR/templates"
trim = false
writer_name = "_w"
escape = { html = "::stilts::escaping::Html", "htm" = "::stilts::escaping::Html" }
Modules§
- escaping
- Contains all the runtime related code for handling opt-out escaping in stilts
Traits§
- Debug
Ext - An extension for types that implement
Debug
- Display
Ext - An extension for types that implement
Display
- Serialize
Ext - An extension to types that implement
Serialize
- Template
- The main template trait that is implemented by the derive macro
Derive Macros§
- Template
- Create a stilts template