askama icon indicating copy to clipboard operation
askama copied to clipboard

Feature request: "middleware" mechanism

Open kazimuth opened this issue 5 years ago • 1 comments

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.

kazimuth avatar Feb 25 '19 22:02 kazimuth

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.

djc avatar Mar 04 '19 20:03 djc