File: partials.rs

package info (click to toggle)
rust-handlebars 5.1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 812 kB
  • sloc: sh: 3; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 924 bytes parent folder | download | duplicates (24)
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
extern crate env_logger;
extern crate handlebars;

use handlebars::Handlebars;
use serde_json::json;
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 = json!({
        "title": "example 0",
        "parent": "base0"
    });
    let data1 = json!({
        "title": "example 1",
        "parent": "base1"
    });

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

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

    Ok(())
}