askama
askama copied to clipboard
Feature request: "middleware" mechanism
I've been noticing it might reduce boilerplate to have something where you could create a "middleware" for each web framework, that would automatically set some properties of templates rendered beneath it. e.g. in actix:
App::new()
.middleware(LoginMiddleware)
.resource("/", |r| r.h(|_| FrontPageTemplate { ... }))
.resource("/control_panel", |r| r.h(|_| ControlPanelTemplate { ... }));
and have the username
field of those templates automatically set to the user's name if they're logged in.
No idea how the hell this could be implemented, especially without too much type tetris.
Maybe with #184 where there's a base template populated somehow that other templates extend?
This could be useful for #211 for providing locale-parsing middlewares.
Hmm, not sure I see it. What you can easily do is have a Meta
type that you put in all the other template contexts and which you pass to views so that they can put it in there.