7 releases

0.2.4 Feb 3, 2021
0.2.3 Dec 11, 2020
0.2.2 Nov 2, 2020
0.2.1 Oct 19, 2020
0.1.1 Jul 12, 2020

#37 in #tera

Download history 22/week @ 2024-11-15 53/week @ 2024-11-22 52/week @ 2024-11-29 89/week @ 2024-12-06 106/week @ 2024-12-13 41/week @ 2024-12-20 28/week @ 2024-12-27 68/week @ 2025-01-03 98/week @ 2025-01-10 84/week @ 2025-01-17 60/week @ 2025-01-24 66/week @ 2025-01-31 99/week @ 2025-02-07 114/week @ 2025-02-14 76/week @ 2025-02-21 54/week @ 2025-02-28

357 downloads per month
Used in tide-admin

MIT/Apache

21KB
99 lines

Tide-Tera Integration

This crate exposes an extension trait that adds two functions to tera::Tera: render_response and render_body. It also adds a convenience context macro for creating ad-hoc tera Contexts.


Crates.io version docs.rs docs
use tera::Tera;
use tide_tera::prelude::*;

#[async_std::main]
async fn main() -> tide::Result<()> {
    tide::log::start();

    let mut tera = Tera::new("examples/templates/**/*")?;
    tera.autoescape_on(vec!["html"]);

    let mut app = tide::with_state(tera);

    app.at("/:name").get(|req: tide::Request<Tera>| async move {
        let tera = req.state();
        let name: String = req.param("name")?;
        tera.render_response("hello.html", &context! { "name" => name })
    });

    app.listen("127.0.0.1:8080").await?;

    Ok(())
}

Dependencies

~17–29MB
~445K SLoC