generated from alecodes/base-template
feat: add minijinja as template engine
This commit is contained in:
parent
5a9b871e42
commit
6cb75aa442
10 changed files with 150 additions and 31 deletions
17
src/router.rs
Normal file
17
src/router.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use axum::{extract::State, response::Html, routing::get, Router};
|
||||
use minijinja::context;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{AppState, ResultTemplate};
|
||||
|
||||
pub fn new() -> Router<Arc<AppState>> {
|
||||
Router::new().route("/", get(handler_home))
|
||||
}
|
||||
|
||||
async fn handler_home(State(state): State<Arc<AppState>>) -> ResultTemplate {
|
||||
let template = state.tmpl_env.get_template("base.html")?;
|
||||
|
||||
let content = template.render(context!())?;
|
||||
|
||||
Ok(Html(content))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue