Expand description
Library for doing server side rendering of HTML using a macro.
§html!
macro
The html!
macro allows to write HTML inside your rust code allowing
to include rust values and instantiate custom
components.
let link = "example.com";
html! {
<div>
"Some literal text "
// In attributes, expressions can be used directly.
<a href=link>
// In bodies braces are required.
{link}
</a>
if 1 < 2 {
<p>
// Whitespace must be inside `"strings"`.
<code> "if" </code> ", " <code> "for" </code>
", and " <code> "while" </code> " can be used as well."
</p>
}
</_> // Closing tags can be inferred.
}
Will result in (with some added whitespace for readability).
<!DOCTYPE html>
<div>
Some literal text <a href="example.com">example.com</a>
<p> <code>if</code>, <code>for</code>, and
<code>while</code> can be used as well. </p>
</div>
Some literal text example.com
if
, for
, and while
can be used as
well.
§Custom Components
The most powerful feature of this crate are custom components. Using the
component
macro, they can be created, based on structs or functions.
Similarly to react or leptos.
#[component]
fn Custom(name: String, link: bool) {
html! {
if link {
<a href=format!("example.com/{name}")>{name}</a>
} else {
{name}
}
}
}
html! {
<Custom name="link" link/>
" "
<Custom name="normal"/>
}
Will result in <a href="example.com/link">link</a> normal
:
link normal
For more documentation see html!
, component
and the examples.
Modules§
- Details on conversion for Attribute values.
- Native HTML elements
Macros§
- The
html!
macro allows constructingHtml
using an HTML like syntax.
Structs§
- Implements
From<impl IntoIterator<Item = impl Into<T>>>
. This means attributes can accept more values. - CSS that can both be put
html!
or returned from an endpoint. - Allows creating an element with arbitrary tag name and attributes.
- HTML
- Embed HTMX script.
- Puts content directly into HTML (or CSS/JS), bypassing HTML-escaping.
Traits§
- Trait used with the custom Rust like JS in
<script>
tags using thehtml!
macro.
Attribute Macros§
- Allows to make a component from a function.