feat: add handlebars
This commit is contained in:
21
__template/handlebars-rust/src/main.rs
Normal file
21
__template/handlebars-rust/src/main.rs
Normal 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(())
|
||||
}
|
||||
Reference in New Issue
Block a user