tera_abstaction_for_actixweb

Crates.iotera_abstaction_for_actixweb
lib.rstera_abstaction_for_actixweb
version0.1.0
sourcesrc
created_at2022-12-14 03:15:10.807981
updated_at2022-12-14 03:15:10.807981
descriptionMakes creating a Tera instance and rendering a template in Actix-Web easier
homepage
repositoryhttps://github.com/GlitchyCrafting/tera_abstraction_for_actixweb.git
max_upload_size
id736266
size2,799
Glitchy Crafting (GlitchyCrafting)

documentation

README

Ex.

use actix_web::{App, HttpServer, web};
use tera::{Tera, Context};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
  HttpServer::new(|| {
      App::new()
        .app_data(web::Data::new(templating::make_instance()))
        .service(index)
  })
  .bind(("0.0.0.0", 3000))?
    .run()
    .await
}

#[get("/")]
async fn index(tera_instance: web::Data<Tera>) -> Result<impl Responder, Error> {
  let mut context = Context::new();
  context.insert("a_key", "a_value");

  templating::render(tera_instance, "template.html".to_string(), context)
}
Commit count: 0

cargo fmt