The page! Macro
The page! macro is the entry point for rendering a full HTML page. Use it inside route handlers to produce a Page struct that your framework serves directly.
Basic Usage
page! accepts the same template syntax as the view! macro: HTML tags, Rust expressions, and control-flow blocks. It creates and returns a Page struct.
1use tidos::{page, Page};2use rocket::{get, routes};34#[get("/")]5pub fn index() -> Page {6 page! {7 <main>8 <h1>{"Hello, world!"}</h1>9 <p>{"Built with Tidos."}</p>10 </main>11 }12}1314#[rocket::main]15async fn main() {16 rocket::build()17 .mount("/", routes![index])18 .launch()19 .await20 .unwrap();21}
Using Components
Any struct implementing the Component trait can be used in your pages.
1use tidos::{page, view, Component, Page};2use rocket::get;34pub struct Greeting {5 pub name: String,6}78impl Component for Greeting {9 fn to_render(&self, page: &mut Page) {10 view! {11 <h1>{"Hello, {}!", &self.name}</h1>12 }13 }14}1516#[get("/")]17pub fn index() -> Page {18 page! {19 <main>20 <Greeting name={"World".to_string()} />21 </main>22 }23}