-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnested.rs
33 lines (29 loc) · 981 Bytes
/
nested.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
use async_std::sync::Arc;
use handlebars::Handlebars;
use std::collections::BTreeMap;
use tide_handlebars::prelude::*;
#[derive(Clone)]
pub struct HandlebarsEngine {
registry: Arc<Handlebars<'static>>,
}
#[async_std::main]
async fn main() -> tide::Result<()> {
tide::log::start();
let mut hb = Handlebars::new();
hb.register_templates_directory(".hbs", "./examples/templates/")
.unwrap();
let engine = HandlebarsEngine {
registry: Arc::new(hb),
};
let mut app = tide::with_state(engine);
app.at("/")
.get(|req: tide::Request<HandlebarsEngine>| async move {
let hb = &req.state().registry;
let mut data0 = BTreeMap::new();
data0.insert("title".to_string(), "hello tide!".to_string());
data0.insert("parent".to_string(), "base".to_string());
Ok(hb.render_response_ext("content", &data0, "html")?)
});
app.listen("127.0.0.1:8080").await?;
Ok(())
}