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.
-
Write your template files in the configurable
template_dirdirectory (default:{rocket_root}/templates). -
Attach
Template::fairing()and return aTemplateusingTemplate::render(), supplying the path of the template file relative totemplate_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.
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.
The 2.x series uses Tera 2.0 and is the primary release and actively supported.
The 1.x series uses Tera 1.0 and exists primarily to ease migrating to this crate. It will be maintained until the end of 2026 (at least).
This was originally forked from the rocket_dyn_templates (3a54d079aef) crate, which was maintained as part of Rocket upstream.