3 unstable releases

0.2.1 Feb 23, 2024
0.2.0 Feb 23, 2024
0.1.0 Feb 3, 2024

#293 in Template engine

21 downloads per month

MIT license

23KB
520 lines

Zinal is a HTML template rendering library for rust programs.

Example

use zinal::*;

#[derive(Template)]
#[template(content = "
  <div>We greet the following people:</div>
  <ul>
  <# for name in &self.names #>
    <Person name={{name}} />
  <#end>
  </ul>
")]
struct Greetings {
  names: Vec<String>
}

#[derive(Template)]
#[template(content = "<li><p>{{self.name}}</p></li>")]
struct Person<'a> {
  name: &'a str,
}

let greetings = Greetings {
  names: vec!["Mary".to_owned(), "John".to_owned(), "Kate".to_owned(), "Agnes".to_owned()]
};

println!("{}", greetings.render_to_string().unwrap());

// Prints (possibly with some insignificant whitespace differences):
// <div>We greet the following people:</div>
// <ul>
// <li><p>Mary</p></li>
// <li><p>John</p></li>
// <li><p>Kate</p></li>
// <li><p>Agnes</p></li>
// </ul>

Dependencies

~115KB