[](https://crates.io/crates/templating)
[](https://docs.rs/templating/latest/templating/)
# Templating
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.
# Tutorial
## Simple templates
You can use the [`html`] macro to create a tamplate like this:
```rust
fn home() -> String {
html! {
<span>
Welcome to my page
</span>
}
}
```
## Expression templates
You can use parentheses to insert a runtime value into the string.
```rust
fn dashboard(user: &str) -> String {
html! {
<h3>
Hello, (user)
</h3>
}
}
```
But if you try this, you will get an unexpected result:
```rust
dashboard("Rust") // => <h3>Hello,Rust</h3>
```
If you want to add an space, you can use templates:
```rust
fn dashboard(user: &str) -> String {
html! {
<h3>
("Hello, ")(user)
</h3>
}
}
```
```
dashboard("Rust") // => <h3>Hello, Rust</h3>
```
## Block templates
You can use block templates to create more complex templates:
```rust
fn store(items: Vec<String>) -> String {
html! {
<ul>
{
for item in items {
html! {
<li>
(item)
</li>
};
}
}
</ul>
}
}
```
[`html`]: crate::html!