lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
1.98k stars 132 forks source link

Document the way to create a full document #423

Open real-felix opened 4 months ago

real-felix commented 4 months ago

Hello, I am using Maud more and more along with htmx, and I really like it. It just took me a bit of time to understand how to return a full document. This is what I came up with:

pub fn document(markup: maud::Markup) -> maud::Markup {
    maud::html! {
        (maud::DOCTYPE)
        html lang="en" {
            head {
                meta charset="UTF-8";
                meta name="viewport" content="width=device-width, initial-scale=1.0";
                link rel="stylesheet" href="index.css";
                script src="https://unpkg.com/htmx.org@1.9.10" {}
                title { "My Cool WebApp" }
            }

            body { (markup) }
        }
    }
}

Maybe it could be documented somewhere?

louiseyousre commented 4 months ago

That's exactly what I came up with too

Anonyfox commented 1 month ago

thats actually a very clean way I'd say. as simple and straightforward as it gets

warsaw commented 1 month ago

I needed exactly this and it works great.