A tiny library for creating string templates, similar to ERB and JSP (angle-bracket-percent tags).
Precompiled along the lines of Askama.
```rust use erst::Template;
pub struct Container<'a> { pub collection: Vec<&'a str>, }
fn main() { println!("{}", Container { collection: vec!["Hello", "<>", "World"] }); } ```
Where simple.erst
looks like:
```erb
Hello!
<% let desc = format!("Here is your list of {} items:", self.collection.len()); -%><%= desc %>
```
And then call it like:
ERST_TEMPLATES_DIR=/path/to/folder-containing-simple-erst cargo run
By default, the template's path
will resolve to a file inside a templates
directory in the current project context (i.e., CARGO_MANIFEST_DIR
).
Note that, unlike Askama
and other template systems, you need to reference any struct members with self
. The template file is basically a function that takes &self
(where self
is the linked container object).
Currently, only the html
type (or none) is supported, with very basic HTML escaping. To unescape HTML content in your template file, wrap the content in erst::Raw("<p>Hello</p>")
.