Template files in Rocket
Published: May 28, 2024
Rocket Templates with the rocket_dyn_templates crate.
[dependencies]
rocket = "0.5.1"
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
#[macro_use] extern crate rocket;
use rocket_dyn_templates::{Template, context};
#[get("/")]
fn dashboard() -> Template {
Template::render("dashboard", context! { username: "eduardo" })
}
#[launch]
fn rocket() -> _ {
// add templating system
rocket::build().attach(Template::fairing())
// register routes
.mount("/dashboard", routes![dashboard])
}
Comments • 0