11 releases

0.2.3 Apr 14, 2024
0.2.2 Mar 1, 2024
0.2.1 Jan 20, 2024
0.1.6 Jan 16, 2024

#128 in Template engine

Download history 25/week @ 2024-01-07 26/week @ 2024-01-14 105/week @ 2024-02-25 19/week @ 2024-03-03 29/week @ 2024-03-10 3/week @ 2024-03-17 22/week @ 2024-03-31 38/week @ 2024-04-07

77 downloads per month

Apache-2.0

49KB
1K SLoC

templr

Documentation Latest version

A templ inspired rust template engine. templr generates Rust code from your templates at compile time using a macro.

Features

  • Template instantiation (with children!)
  • Context for passing info deep
  • Rust-like for, if-else, if-let, match, and let statements (allowed in start tags!)
  • Full rust variables
  • Opt-out HTML escaping
  • Nice attributes
  • We have a formatter: templrfmt!
  • Optional built-in support for Actix-Web, Axum, Gotham, Rocket, Salvo, Tide, and Warp web frameworks.

How to get started

First, add the templr dependancy to your crate's Cargo.toml:

cargo add templr

In any Rust file inside your crate, add the following:

use templr::{Template, templ, templ_ret};

pub fn hello(name: &str) -> templ_ret!['_] {
    templ! {
        <p>Hello, {name}!</p>
    }
}

fn main() {
    let html = hello("world").render(&()).unwrap();
    println!("{html}");
}

You should be able to compile and run this code.

Dependencies

~0.4–38MB
~573K SLoC