| Crates.io | rshtml |
| lib.rs | rshtml |
| version | 0.5.0 |
| created_at | 2025-06-08 19:01:13.080239+00 |
| updated_at | 2026-01-20 12:30:44.380523+00 |
| description | RsHtml: A Template Engine for Seamless HTML and Rust Integration. |
| homepage | |
| repository | https://github.com/rshtml/rshtml |
| max_upload_size | |
| id | 1705175 |
| size | 47,010 |
RsHtml is a compile-time, type-safe, lightweight, and flexible template engine for Rust. It aims to seamlessly integrate Rust code with HTML content. It allows developers to write dynamic templates that embed Rust expressions and makes it easier to generate HTML content programmatically. It generates efficient Rust code for template rendering at compile time.

See the Documentation for a full list of features and the Editor Support section for editor integration details. A minimal working website example is also available in the rshtml_test crate.
<div>{ code() }</div>) and embedding the resulting expressions into the template. let user_info = v!(<p>name: {user.name}</p>);
v! {
<div class="user-info"> {user_info} </div>
}
fn cards(cards: &[Card]) -> impl View {
let mut card_views = Vec::new();
for card in cards {
card_views.push(v!(<div class="card">{&card.title}</div>));
}
v! {
<div>
{ card_views }
</div>
}
}
impl View for Home {
fn render(&self, out: &mut dyn Write) -> Result {
v!(<p>Home Page {&self.title}</p>).render(out)
}
}
.rs.html templates from the default views directory.@ prefix or HTML-like component syntax (e.g., <Component/>).@if, @else), loops (@for), and pattern matching (@match).@{}), various Rust expression syntaxes (e.g., @expression, @(expression), and a broad range of other Rust syntax.@time()).@raw blocks and server-side comments with @* ... *@.<h1>Welcome to RsHtml</h1>
@use "Component.rs.html" as Component
<Component title="home" is_ok=true>
<p>child content</p>
</Component>
@if self.is_logged_in {
<p>Hello, @self.username!</p>
} else {
<p>Please log in to continue.</p>
}
<ul>
@for item in self.items {
<li>@item</li>
}
</ul>
@{
let x = 42;
let y = x * 2;
println!("Debug: x = {}, y = {}", x, y);
}
@* This is a comment and will not appear in the output *@
use rshtml::{RsHtml, traits::RsHtml};
#[derive(RsHtml)]
struct HomePage { // Looks for home.rs.html in views folder.
title: String,
}
fn main() {
let homepage = HomePage {
title: "Home Page".to_string()
};
let result = homepage.render().unwrap();
print!("{}", result);
}
To use RsHtml in your Rust project, run cargo add rshtml command or add it as a dependency in your Cargo.toml:
[dependencies]
rshtml = "0.5.0"
# For RsHtml derive macro:
# The default folder can be changed. This is the default setup:
[package.metadata.rshtml]
views = { path = "views", extract_file_on_debug = false }
Contributions are welcome! Feel free to open issues or submit pull requests to improve RsHtml.