pub struct Renderer { /* private fields */ }Expand description
Axum extractor for rendering MiniJinja templates.
Renderer is extracted from a handler’s argument list and provides three render
methods:
html— renders a template and returnsHtml<String>.html_partial— renders the partial template when the request is an HTMX request, or the full page template otherwise.string— renders a template and returnsString.
The handler’s context argument is merged with the middleware-populated
TemplateContext; handler values override middleware values on conflict.
§Requirements
Enginemust be registered in thecrate::service::AppStateregistry.TemplateContextLayermust be installed as a middleware layer on the router.
§Example
use modo::template::{Renderer, context};
use axum::response::Html;
async fn home(renderer: Renderer) -> modo::Result<Html<String>> {
renderer.html("pages/home.html", context! { title => "Home" })
}Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn html_partial(
&self,
page: &str,
partial: &str,
context: Value,
) -> Result<Html<String>>
pub fn html_partial( &self, page: &str, partial: &str, context: Value, ) -> Result<Html<String>>
Renders partial if the request was issued by HTMX, otherwise renders page.
This is the primary method for HTMX-driven partial updates: the full page
template is used for initial page loads, while partial is used for subsequent
HTMX swaps.
§Errors
Returns Error if the selected template is not found or
rendering fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl UnsafeUnpin for Renderer
impl !UnwindSafe for Renderer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.