Implement basic templating

rust
Elnu 2 years ago
parent 234458e11c
commit 1cf099845b

1385
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -7,3 +7,5 @@ edition = "2021"
[dependencies] [dependencies]
rocket = "=0.5.0-rc.3" rocket = "=0.5.0-rc.3"
rocket_contrib = { version = "0.4.11", features = ["templates"] }
rocket_dyn_templates = { version = "0.1.0-rc.3", features = ["tera"] }

@ -0,0 +1,2 @@
[default]
template_dir = "templates"

@ -1,11 +1,19 @@
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
use rocket_dyn_templates::{Template, context};
#[get("/")] #[get("/")]
fn index() -> &'static str { fn index() -> Template {
"Hello, world!" Template::render("index", context! {
challenge: 114,
})
} }
#[launch] #[launch]
fn rocket() -> _ { fn rocket() -> _ {
rocket::build().mount("/", routes![index]) let config = rocket::Config::figment()
.merge(("port", 1313));
rocket::custom(config)
.mount("/", routes![index])
.attach(Template::fairing())
} }

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Tegaki Tuesday</title>
</head>
<body>
<h1>Welcome to Tegaki Tuesday #{{ challenge }}!</h1>
</body>
</html>
Loading…
Cancel
Save