pub struct TemplateContextLayer;Expand description
Tower middleware layer that populates TemplateContext for every request.
Install this layer on your router before any handler that uses
Renderer. The layer injects the following keys into
the request’s TemplateContext:
| Key | Source |
|---|---|
current_url | request.uri().to_string() |
is_htmx | HX-Request: true header |
request_id | X-Request-Id header (if present) |
locale | Translator in extensions (present only when I18nLayer is installed upstream) |
csrf_token | CsrfToken extension (if present) |
flash_messages | Callable returning flash entries; FlashState extension must be set by FlashLayer |
tier_name | TierInfo::name (when TierInfo extension is present) |
tier_has | Template function tier_has(name) -> bool (when TierInfo is present) |
tier_enabled | Template function tier_enabled(name) -> bool (when TierInfo is present) |
tier_limit | Template function tier_limit(name) -> Option<u64> (when TierInfo is present) |
This layer reads the current request’s
Translator (installed by
I18nLayer) and exposes locale to templates.
If no I18nLayer is upstream, the locale variable is simply absent from
the template context.
This layer is also re-exported as
modo::middlewares::TemplateContext
for convenience at wiring sites.
§Example
use modo::template::TemplateContextLayer;
let router: axum::Router = axum::Router::new()
// ... routes ...
.layer(TemplateContextLayer::new());Implementations§
Source§impl TemplateContextLayer
impl TemplateContextLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new TemplateContextLayer.
Trait Implementations§
Source§impl Clone for TemplateContextLayer
impl Clone for TemplateContextLayer
Source§fn clone(&self) -> TemplateContextLayer
fn clone(&self) -> TemplateContextLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for TemplateContextLayer
impl Default for TemplateContextLayer
Source§fn default() -> TemplateContextLayer
fn default() -> TemplateContextLayer
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TemplateContextLayer
impl RefUnwindSafe for TemplateContextLayer
impl Send for TemplateContextLayer
impl Sync for TemplateContextLayer
impl Unpin for TemplateContextLayer
impl UnsafeUnpin for TemplateContextLayer
impl UnwindSafe for TemplateContextLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more