tide-tera

Use tera templates on tide

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
Download history 181/week @ 2024-07-20 116/week @ 2024-07-27 98/week @ 2024-08-03 77/week @ 2024-08-10 32/week @ 2024-08-17 39/week @ 2024-08-24 44/week @ 2024-08-31 78/week @ 2024-09-07 35/week @ 2024-09-14 62/week @ 2024-09-21 86/week @ 2024-09-28 43/week @ 2024-10-05 74/week @ 2024-10-12 54/week @ 2024-10-19 50/week @ 2024-10-26 51/week @ 2024-11-02

231 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

~16–28MB
~425K SLoC