Rust Maud Templates

How to build parent templates/partials with Rust in maud, using a simple functional component.


This is how a "global" or "outer" template can be built as a component, including doctype, head and body:

use maud::{html, Markup};

fn layout(title: &str, content: Markup) -> Markup {
    html! {
        (maud::DOCTYPE)
        html lang="en" {
            head {
						    meta charset="UTF-8";
                meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no";
								title { (title) }
						}
            body {
                main class="container flex-shrink-0 py-5" {
                    { (content) }
                }
            }
        }
    }
}

And this is how it can be used:

use maud::{html, Markup};

fn page() -> Markup {
    layout("Awesome Landingpage!", html! {
        (maud::DOCTYPE)
        html lang="en" {
            head {
						    meta charset="UTF-8";
                meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no";
								title { (title) }
						}
            body {
                main class="container flex-shrink-0 py-5" {
                    { (content) }
                }
            }
        }
    })
}

Linked Technologies

What it's made of

illustration of Actix-Web
Actix-Web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust. It runs on top of tokio and is probably the most mature rust web framework, with lots of available crates.

illustration of HTML
HTML

The backbone of the web. Master it to craft structured, accessible content for any online project, from simple sites to complex applications!

illustration of Rust
Rust

A language empowering everyone to build reliable and efficient software. Futuristic swiss army knife and probably the most powerful mainstream technology today

Linked Categories

Where it's useful

illustration of Backend Development
Backend Development

Uncover the power behind the scenes of web services and applications, focusing on creating robust, scalable backend systems that support frontend experiences.

illustration of Frontend Development
Frontend Development

Explore the latest tools and techniques for crafting responsive designs, enhancing user interfaces, and optimizing web performance.

illustration of Software Architecture
Software Architecture

Dive into the world of Software Architecture where design meets functionality. Explore frameworks, patterns, and best practices that define the structure of software systems, making them robust, scalable, and maintainable.