- register_template_string
- render
Quick start - registered template
- In this example we register a template to make it easier to reuse it and then use it twice.
examples/handlebars/handlebars-separate-functions/src/main.rs
use handlebars::Handlebars; use serde_json::json; use std::error::Error; fn main() { match render() { Ok(_) => println!(), Err(_) => println!("error"), } } fn render() -> Result<(), Box<dyn Error>> { let mut reg = Handlebars::new(); reg.register_template_string("tpl_1", "Good afternoon, {{name}}")?; println!("{}", reg.render("tpl_1", &json!({"name": "foo"}))?); println!("{}", reg.render("tpl_1", &json!({"name": "bar"}))?); Ok(()) }
examples/handlebars/handlebars-separate-functions/out.html
Good afternoon, foo Good afternoon, bar
examples/handlebars/handlebars-separate-functions/Cargo.toml
[package] name = "handlebars-quick" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] handlebars = "4.3.7" serde_json = "1.0.97"