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 templates. With the default
derive feature, it also re-exports the TemplateSimple, TemplateOnce,
TemplateMut, and Template derive macros. A separate dependency on
sailfish-macros is not required.
Use TemplateSimple for direct field access, or TemplateOnce,
TemplateMut, and Template to access fields and methods through self.
The latter traits render by consuming the context, mutably borrowing it, or
borrowing it through a shared reference, respectively.
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(source = "<% for msg in &self.messages { %><div><%= msg %></div><% } %>")]
struct HelloTemplate {
messages: Vec<String>,
}
let ctx = HelloTemplate {
messages: vec!["foo".to_string(), "bar".to_string()],
};
assert_eq!(ctx.render()?, "<div>foo</div><div>bar</div>");Re-exports§
pub use runtime::RenderError;pub use runtime::RenderResult;
Modules§
- runtime
- Sailfish runtime
Traits§
- Template
- Template that can be rendered repeatedly through a shared reference.
- Template
Mut - Template that can be rendered repeatedly through a mutable reference.
- Template
Once - Template that consumes its context and accesses fields and methods through
self. - Template
Simple - Template that consumes its context and exposes fields without using
self.
Derive Macros§
- Template
derive - Template
Mut derive - Template
Once derive - Template
Simple derive