tera icon indicating copy to clipboard operation
tera copied to clipboard

Passing in a user context on every render

Open dennismarwood opened this issue 2 years ago • 1 comments

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

dennismarwood avatar Jun 28 '23 22:06 dennismarwood

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

Keats avatar Jun 29 '23 07:06 Keats