templr

Crates.iotemplr
lib.rstemplr
version0.2.4
sourcesrc
created_at2024-01-09 21:52:33.520029
updated_at2024-10-22 15:54:19.677698
descriptionA rust template library
homepagehttps://github.com/PizzasBear/templr
repositoryhttps://github.com/PizzasBear/templr
max_upload_size
id1094667
size42,783
PizzasBear (PizzasBear)

documentation

https://docs.rs/templr

README

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.

Commit count: 33

cargo fmt