#actix-web #web #tera #instance #template #rendering

yanked tera_abstaction_for_actixweb

Makes creating a Tera instance and rendering a template in Actix-Web easier

0.1.0 Dec 14, 2022

#46 in #tera

GPL-3.0-or-later

3KB

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)
}

Dependencies

~24–36MB
~630K SLoC