#[macro_use] extern crate tenjin; use std::io; use tenjin::*; struct Context<'a> { header: &'a str, people: &'a [User<'a>], } struct User<'a> { first: &'a str, last: &'a str, weight: usize, html: &'a str, } context! { self: ('a) Context<'a> { header => @raw self.header, // Will NOT be escaped. people => @iter self.people, } self: ('a) User<'a> { name => @{ first => self.first, last => self.last, }, weight => self.weight, html => self.html, // WILL be escaped. } } fn main() { let mut tenjin = Tenjin::empty(); tenjin.register("test", Template::compile(" { header } First Name: {{ person.name.first }} Last Name: {{ person.name.last }} Weight: {{ person.weight }} kg { for person in people } First Name: { person.name.first } Last Name: { person.name.last } Weight: { person.weight } kg Fav. HTML: { person.html } { end } ").unwrap()); let data = Context { header: "
Tactical genius?" }, ], }; let output = io::stdout(); let template = tenjin.get("test").unwrap(); tenjin.render(template, &data, &mut output.lock()).unwrap(); }