pub struct Template { /* private fields */ }Expand description
Template for composing multiple semantic elements into a page structure.
Provides a high-level API for building accessible HTML5 document layouts.
§Examples
use html_generator::elements::Template;
let page = Template::new()
.nav("Main navigation", "<ul><li>Home</li></ul>")
.main_content("<h1>Welcome</h1><p>Content here.</p>")
.aside("Related", "<p>Related links</p>")
.build();
assert!(page.contains("<nav"));
assert!(page.contains("<main"));
assert!(page.contains("<aside"));Implementations§
Source§impl Template
impl Template
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty template.
§Examples
use html_generator::elements::Template;
let html = Template::new().build();
assert!(html.is_empty());Adds a navigation section.
§Examples
use html_generator::elements::Template;
let html = Template::new().nav("Primary", "<a href='/'>Home</a>").build();
assert!(html.contains("<nav"));
assert!(html.contains(r#"aria-label="Primary""#));Sourcepub fn header(self, content: &str) -> Self
pub fn header(self, content: &str) -> Self
Adds a header section.
§Examples
use html_generator::elements::Template;
let html = Template::new().header("<h1>Site</h1>").build();
assert!(html.contains("<header><h1>Site</h1></header>"));Sourcepub fn main_content(self, content: &str) -> Self
pub fn main_content(self, content: &str) -> Self
Adds the main content area.
§Examples
use html_generator::elements::Template;
let html = Template::new().main_content("<p>Body</p>").build();
assert!(html.contains("<main"));
assert!(html.contains(r#"role="main""#));Sourcepub fn section(self, label: &str, content: &str) -> Self
pub fn section(self, label: &str, content: &str) -> Self
Adds a section to the template.
§Examples
use html_generator::elements::Template;
let html = Template::new().section("Intro", "<p>Hi</p>").build();
assert!(html.contains("<section"));
assert!(html.contains(r#"aria-label="Intro""#));Sourcepub fn aside(self, label: &str, content: &str) -> Self
pub fn aside(self, label: &str, content: &str) -> Self
Adds an aside section.
§Examples
use html_generator::elements::Template;
let html = Template::new().aside("Related", "<p>links</p>").build();
assert!(html.contains("<aside"));Adds a footer section.
§Examples
use html_generator::elements::Template;
let html = Template::new().footer("© 2026").build();
assert!(html.contains("<footer"));
assert!(html.contains(r#"role="contentinfo""#));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnsafeUnpin for Template
impl UnwindSafe for Template
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