-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtera.rs
44 lines (37 loc) · 1.01 KB
/
tera.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use rocket::Request;
use rocket::response::Redirect;
use rocket_dyn_templates::{Template, tera::Tera, context};
#[get("/")]
pub fn index() -> Redirect {
Redirect::to(uri!("/tera", hello(name = "Your Name")))
}
#[get("/hello/<name>")]
pub fn hello(name: &str) -> Template {
Template::render("tera/index", context! {
title: "Hello",
name: Some(name),
items: vec!["One", "Two", "Three"],
})
}
#[get("/about")]
pub fn about() -> Template {
Template::render("tera/about.html", context! {
title: "About",
})
}
#[catch(404)]
pub fn not_found(req: &Request<'_>) -> Template {
Template::render("tera/error/404", context! {
uri: req.uri()
})
}
pub fn customize(tera: &mut Tera) {
tera.add_raw_template("tera/about.html", r#"
{% extends "tera/base" %}
{% block content %}
<section id="about">
<h1>About - Here's another page!</h1>
</section>
{% endblock content %}
"#).expect("valid Tera template");
}