Expand description
Sailfish is a simple, small, and extremely fast template engine for Rust. Before reading this reference, I recommend reading User guide.
This crate contains utilities for rendering sailfish template.
If you want to use sailfish templates, import sailfish-macros
crate and use
derive macro #[derive(TemplateOnce)]
, #[derive(TemplateMut)]
or #[derive(Template)]
.
In most cases you don’t need to care about the runtime
module in this crate, but
if you want to render custom data inside templates, you must implement
runtime::Render
trait for that type.
ⓘ
use sailfish::Template;
#[derive(Template)]
#[template(path = "hello.stpl")]
struct HelloTemplate {
messages: Vec<String>
}
fn main() {
let ctx = HelloTemplate {
messages: vec!["foo".to_string(), "bar".to_string()]
};
println!("{}", ctx.render().unwrap());
}
Re-exports§
pub use runtime::RenderError;
pub use runtime::RenderResult;
Modules§
- Sailfish runtime
Traits§
- Template that can be rendered any number of times.
- Template that is mutable and can be rendered any number of times.
- Template that can be rendered with consuming itself.
- Template which can be accessed without using
self
.
Derive Macros§
- Template
derive
- Template
Mut derive
- Template
Once derive
- Template
Simple derive