| Crates.io | templating |
| lib.rs | templating |
| version | 0.1.2 |
| created_at | 2025-05-10 22:32:23.992999+00 |
| updated_at | 2025-05-10 22:38:39.23194+00 |
| description | Simple HTML templating for Rust. |
| homepage | |
| repository | https://github.com/Surjuu/templating |
| max_upload_size | |
| id | 1668887 |
| size | 15,093 |
This crate provides the html macro for creating HTML templates in a
simple way. More information about the macro can be found in its
documentation.
You can use the html macro to create a tamplate like this:
fn home() -> String {
html! {
<span>
Welcome to my page
</span>
}
}
You can use parentheses to insert a runtime value into the string.
fn dashboard(user: &str) -> String {
html! {
<h3>
Hello, (user)
</h3>
}
}
But if you try this, you will get an unexpected result:
dashboard("Rust") // => <h3>Hello,Rust</h3>
If you want to add an space, you can use templates:
fn dashboard(user: &str) -> String {
html! {
<h3>
("Hello, ")(user)
</h3>
}
}
dashboard("Rust") // => <h3>Hello, Rust</h3>
You can use block templates to create more complex templates:
fn store(items: Vec<String>) -> String {
html! {
<ul>
{
for item in items {
html! {
<li>
(item)
</li>
};
}
}
</ul>
}
}