| 1 | extern crate env_logger; |
| 2 | extern crate handlebars; |
| 3 | |
| 4 | use handlebars::Handlebars; |
| 5 | use serde_json::json; |
| 6 | use std::error::Error; |
| 7 | |
| 8 | fn main() -> Result<(), Box<dyn Error>> { |
| 9 | env_logger::init(); |
| 10 | let mut handlebars = Handlebars::new(); |
| 11 | |
| 12 | handlebars.register_template_file("template", "./examples/partials/template2.hbs")?; |
| 13 | |
| 14 | handlebars.register_template_file("base0", "./examples/partials/base0.hbs")?; |
| 15 | handlebars.register_template_file("base1", "./examples/partials/base1.hbs")?; |
| 16 | |
| 17 | let data0 = json!({ |
| 18 | "title": "example 0", |
| 19 | "parent": "base0" |
| 20 | }); |
| 21 | let data1 = json!({ |
| 22 | "title": "example 1", |
| 23 | "parent": "base1" |
| 24 | }); |
| 25 | |
| 26 | println!("Page 0"); |
| 27 | println!("{}", handlebars.render("template", &data0)?); |
| 28 | println!("======================================================="); |
| 29 | |
| 30 | println!("Page 1"); |
| 31 | println!("{}", handlebars.render("template", &data1)?); |
| 32 | |
| 33 | Ok(()) |
| 34 | } |