Crates.io | tide-tera |
lib.rs | tide-tera |
version | 0.2.4 |
source | src |
created_at | 2020-07-11 23:28:24.95161 |
updated_at | 2021-02-03 22:17:23.544097 |
description | Use tera templates on tide |
homepage | |
repository | https://github.com/jbr/tide-tera |
max_upload_size | |
id | 264226 |
size | 70,505 |
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.
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(())
}