Skip to main content

view

Attribute Macro view 

Source
#[view]
Expand description

Adds serde::Serialize, axum::response::IntoResponse, and ViewRender implementations to a struct, linking it to a MiniJinja template.

ยงSyntax

#[view("templates/page.html")]
#[view("templates/page.html", htmx = "templates/partial.html")]

The macro derives serde::Serialize on the struct and implements axum::response::IntoResponse by serializing the struct as the template context and rendering the named template. When the optional htmx path is provided, HTMX requests (HX-Request header present) render the partial instead of the full-page template.

Can only be applied to structs.

Requires the templates feature on modo.