5 releases

0.2.1 Mar 1, 2024
0.2.0 Jan 20, 2024
0.1.2 Jan 15, 2024
0.1.1 Jan 9, 2024
0.1.0 Jan 9, 2024

#558 in Template engine

Download history 23/week @ 2024-01-04 44/week @ 2024-01-11 14/week @ 2024-01-18 2/week @ 2024-02-22 120/week @ 2024-02-29 11/week @ 2024-03-07 10/week @ 2024-03-14 3/week @ 2024-03-28 107/week @ 2024-04-04

122 downloads per month
Used in 4 crates (2 directly)

Apache-2.0

53KB
1.5K 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

~295–740KB
~18K SLoC