| Crates.io | sjabloon |
| lib.rs | sjabloon |
| version | 0.0.2 |
| created_at | 2025-04-29 18:42:41.431267+00 |
| updated_at | 2025-05-06 16:27:40.344861+00 |
| description | a crate for templating html |
| homepage | |
| repository | https://github.com/snx-rs/sjabloon |
| max_upload_size | |
| id | 1653914 |
| size | 11,273 |
sjabloon is a modern templating engine for Rust with a JSX-like syntax. writing templates is comparable to writing JSX on the server.
you can define templates using the template macro. this macro will be
transpiled to a format macro call at build-time, which will result in a
string at run-time. "components" are just functions/closures which return a
string.
fn article(article: Article) -> String {
template! {
<a href=format!("articles/{}", article.slug)>
<article>
<img
src=article.cover.url
alt=article.cover.alt
width="400"
height="200"
/>
<h2>{article.title}</h2>
<small>author: {article.author}</small>
</article>
</a>
}
}
fn articles_list(articles: Vec<Article>) -> String {
template! {
<section>
<h1>articles</h1>
<ul>
{articles.into_iter().map(article).collect::<Vec<String>>().join("")}
</ul>
</section>
}
}