Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.5k stars 281 forks source link

Passing in a user context on every render #837

Open dennismarwood opened 1 year ago

dennismarwood commented 1 year ago

My apologies if this is obvious but how would I go about passing along user session data "automatically"? I have a base template that checks if a user session is present. Is there a better way to get that data to the template without manually adding it to the context before each render? Maybe a custom tera function that can somehow load that data in the context if it is available?

I am a greener developer so it may be something obvious that I have missed. Using Rocket.

Thanks

Keats commented 1 year ago

Well a user session will be different on every request, so you would need to (i have never used Rocket so i don't know if what i'm going to say is possible) either create the context in a middleware but that wouldn't be very smart perf wise, have some helper function that generates the base context for tera (eg render_template(route_context: Context, session: Session)) or a macro