summaryrefslogtreecommitdiffstats
path: root/vendor/handlebars/examples/partials.rs
blob: 80b20c2f777bc1f703a3a7ebce0e5837365c2aab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
extern crate env_logger;
extern crate handlebars;
#[macro_use]
extern crate maplit;

use handlebars::Handlebars;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    env_logger::init();
    let mut handlebars = Handlebars::new();

    handlebars.register_template_file("template", "./examples/partials/template2.hbs")?;

    handlebars.register_template_file("base0", "./examples/partials/base0.hbs")?;
    handlebars.register_template_file("base1", "./examples/partials/base1.hbs")?;

    let data0 = btreemap! {
        "title".to_string() => "example 0".to_string(),
        "parent".to_string() => "base0".to_string()
    };
    let data1 = btreemap! {
        "title".to_string() => "example 1".to_string(),
        "parent".to_string() => "base1".to_string()
    };

    println!("Page 0");
    println!("{}", handlebars.render("template", &data0)?);
    println!("=======================================================");

    println!("Page 1");
    println!("{}", handlebars.render("template", &data1)?);

    Ok(())
}