feat: add template

This commit is contained in:
2020-12-06 11:08:07 +08:00
parent 0e9b83fad1
commit 8b5e9e54c1
7 changed files with 280 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
use askama::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 root
struct HelloTemplate<'a> { // the name of the struct can be anything
name: &'a str, // the field name should match the variable name
// in your template
}
fn main() {
let hello = HelloTemplate { name: "world" }; // instantiate your struct
println!("{}", hello.render().unwrap()); // then render it.
}