Last active
June 12, 2020 18:47
-
-
Save bpremo/f552835fec1efab82cda53d95dddb8c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate tera; | |
| extern crate serde; | |
| use tera::Tera; | |
| use tera::Context; | |
| use serde::{Serialize}; | |
| #[derive(Serialize)] | |
| struct Person { | |
| name: String, | |
| action: String, | |
| } | |
| fn main() { | |
| let scott = Person{name:String::from("Scott"), action:String::from("sucks")}; | |
| let brandon = Person{name:String::from("Brandon"), action:String::from("ROCKS")}; | |
| let people = vec![&scott, &brandon]; | |
| let mut tera = Tera::default(); | |
| let _ = match tera.add_raw_template("test", "{{ person.name }} {{ person.action }}!") { | |
| Ok(t) => t, | |
| Err(e) => { | |
| println!("Parsing error(s): {}", e); | |
| ::std::process::exit(1); | |
| } | |
| }; | |
| for person in people.iter() { | |
| let mut context = Context::new(); | |
| context.insert("person", &person); | |
| let res = match tera.render("test", &context) { | |
| Ok(t) => t, | |
| Err(e) => { | |
| println!("Parsing error(s): {}", e); | |
| ::std::process::exit(1); | |
| } | |
| }; | |
| println!("{}", res) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment