4 ms·
Any recommendations for rust template engines? I'd like something that can easily render labeled fragments of a template instead of requiring me to split a page
by infogulch 3y ago
Any recommendations for rust template engines? I'd like something that can easily render labeled fragments of a template instead of requiring me to split a page into a dozen little files. Kinda like inline {{block}} definitions in Go's html/template. Speed is also nice.
From template-benchmark-rs [0] I found sailfish [1] (fast, but no fragments(?)). render-rs [2] and syn-rsx [3] both let you write html in rust macros which is cool (maybe that can substitute for fragments?). Then there's gtmpl-rust [4] which is just Go templates reimplemented in rust.
[0]: https://github.com/rosetta-rs/template-benchmarks-rs https://github.com/rosetta-rs/template-benchmarks-rs
[1]: https://github.com/rust-sailfish/sailfish https://github.com/rust-sailfish/sailfish
[2]: https://github.com/render-rs/render.rs https://github.com/render-rs/render.rs last updated Jul 2020
[3]: https://github.com/stoically/syn-rsx https://github.com/stoically/syn-rsx last updated Nov 2022
[4]: https://github.com/fiji-flo/gtmpl-rust https://github.com/fiji-flo/gtmpl-rust
- tomjakubowski 3y agotera is fairly standard. Jinja2-like syntax. I'm not sure what you mean about rendering labeled fragments, do you have an example?
- infogulch 3y agoSure. They're called 'partials' sometimes. Useful if you want to rerender just part of a page. This is a pattern used by HTMX, a 'js framework' that accepts fragments of html in an http response and injects it into the page. This is good because it avoids the flash and state loss of a whole page reload. See the HTMX essay on template fragments for a more complete argument [0]. This is a go template for an interactive todos app [1] that I'm experimenting with. The html content of the entire page is present in one template definition which is split into 6 inline {{block}} definitions / "fragments". The page supports 5 interactions indicated by {{define}} definitions, each of which reuse various block fragments relevant to that interaction. I'm in the process of converting it to use embedded cozodb [2] queries which act as a server side data store. The idea here is that the entire 'app', including all html fragments, styles, http requests and responses, db schema, and queries are embedded into this single 100-line file. [0]: https://htmx.org/essays/template-fragments/ https://htmx.org/essays/template-fragments/ [1]: https://github.com/infogulch/go-htmx/blob/master/templates/todos.html https://github.com/infogulch/go-htmx/blob/master/templates/t... [2]: https://github.com/cozodb/cozo https://github.com/cozodb/cozo
- langfan 3y ago>Sure. They're called 'partials' sometimes. Same as partials in Rails, maybe. A while since I used it.
- prussian 3y agohttps://maud.lambda.xyz/ https://maud.lambda.xyz/ Maybe this?