rocket_tera 1.0.0

Tera templating integration for Rocket.
Documentation

rocket_tera crates.io

This crate adds support for using Tera with Rocket. It automatically discovers templates, provides a Responder to render templates, and automatically reloads templates when compiled in debug mode.

Usage

  1. Write your template files in the configurable template_dir directory (default: {rocket_root}/templates).

  2. Attach Template::fairing() and return a Template using Template::render(), supplying the path of the template file relative to template_dir:

    use rocket_tera::{Template, context};
    
    #[get("/")]
    fn index() -> Template {
        Template::render("index.html", context! { field: "value" })
    }
    
    #[launch]
    fn rocket() -> _ {
        rocket::build().attach(Template::fairing())
    }
    

See the crate docs for full details.

Security

This crate is intended to be used with trusted templates that are shipped alongside your Rocket application. Using untrusted or user-provided templates is out of scope of this crate's threat model.

History

This was originally forked from the rocket_dyn_templates crate, which was maintained as part of Rocket upstream.