Core Concepts
Templating
Learn how to render content using your favorite templating engine.
In general, if a library can return a String, you can use it to generate pages with Maudit.
Through crate features, Maudit includes built-in helper methods and traits implementation for popular templating libraries.
Maud
Maudit implements Into<RenderResult>
for the Maud Markup
type, allowing one to directly return Maud's templates from a route's render
method.
use maud::{html, Markup};
use maudit::route::prelude::*;
#[route("/")]
pub struct Index;
impl Route for Index {
fn render(&self, _: &mut PageContext) -> impl Into<RenderResult> {
html! {
h1 { "Hello, world!" }
}
}
}
Maudit implements the Render
trait for assets, such as scripts, styles, and images, allowing one to use them directly in Maud templates.
use maud::{html, Markup};
use maudit::route::prelude::*;
#[route("/")]
pub struct Index;
impl Route for Index {
fn render(&self, ctx: &mut PageContext) -> impl Into<RenderResult> {
let logo = ctx.add_image("./logo.png");
html! {
(logo) // Will generate <img src="IMAGE_PATH" width="IMAGE_WIDTH" height="IMAGE_HEIGHT" loading="lazy" decoding="async" />
}
}
}
To use Maud with Maudit, install Maud into your project by adding it to your Cargo.toml
, or running cargo add maud
.
[dependencies]
maud = "0.27"
The maud
feature is enabled by default. If you have disabled default features, enable it manually:
maudit = { version = "0.6", features = ["maud"] }