feat: add handlebars

This commit is contained in:
2020-12-26 09:58:53 +08:00
parent 9a0434868b
commit ec29c2368c
3 changed files with 276 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#[macro_use] extern crate serde_json;
use std::error::Error;
use handlebars::Handlebars;
fn main() -> Result<(), Box<dyn Error>> {
let mut reg = Handlebars::new();
// render without register
println!(
"{}",
reg.render_template("Hello {{name}}", &json!({"name": "foo"}))?
);
// register template using given name
reg.register_template_string("tpl_1", "Good afternoon, {{name}}")?;
println!(
"{}",
reg.render("tpl_1", &json!({"name": "foo"}))?
);
Ok(())
}