Skip to main content

Module context

Module context 

Source
Expand description

Task-local request context for layout-level template data.

Askama can’t reach request state, so flash messages and current user are carried in a [tokio::task_local!] populated by request_ctx middleware and read by layout partials via flashes and current_user. Outside a request scope, accessors return defaults — no task-local setup needed for direct-render template unit tests.

Structs§

CurrentUser
Minimal view of the signed-in user for templates. Excludes password_hash so templates can’t read sensitive data via current_user.
SwitcherLeague
One entry in the overflow menu’s league switcher.

Functions§

current_contest
The Current Contest id — None off-season (hides the Current tab), on non-GET/htmx requests, on the root redirect, and outside a request scope.
current_team
The signed-in user’s team — the tab bar’s My Team link.
current_user
The signed-in user, or None when unauthenticated or outside a request scope.
flashes
Drain pending flash messages for this request, plus the implicit league-switch toast when an entity link changed the active league. Returns empty outside a request scope.
league_name
The current league’s name — the <title> suffix. None when signed out, pre-league, or outside a request scope.
league_switcher
The switcher entries: the user’s team leagues, lowest id first. Empty for users with fewer than two leagues (no switcher shown) and outside a request scope.
request_ctx
Build the request context and run the rest of the stack inside the task-local scope. Must be mounted inside MessagesManagerLayer and the auth layer so both extensions are populated.