Rust templating with Handlebars.
Thanks to @blaenk's patch, handlebars-rust now compiles on nightly, beta and stable (1.4.0+) channel.
Check examples in the source. The example shows you how to:
- Create a
Handlebarsand register the template from files
- Create a custom Helper with closure or struct implementing
HelperDef, and register it
- Render something
cargo run --example render to see results.
RUST_LOG=handlebars=info cargo run --example render for logging output).
examples/ for more concrete demos of current API.
For information about handlebars, you will go to handlebars.js.
Reasons I prefer Handlebars:
- Never ruin your Rust with HTML
- Never ruin your HTML with Rust
- Templating without a reuse mechanism is shit
- Templating without customization is nothing but shit
- Separation of Rust and HTML
- A few control structures makes templating easier
- Few control structures stops you to put logic into templates
- Template reuse with include(
- Customize template behavior with helpers
- As a static typed language, it's a little verbose to use handlebars
- You will have to make your data
ToJson-able, so we can render it. If you are on nightly channel, we have a syntax extension to generate default
ToJsonimplementation for you.
Handlebars-js features supported in Handlebars-rust
- Expression / Block Helpers
- Built-in helpers
- Customizing helper
- Parameter and hashes for helper
- Partials, include
- Omitting whitespace with
- Json expression
Feel free to report an issue if you find something broken. We aren't going to implement all features of handlebars-js, but we should have a workaround for cases we don't support.
Handlebars for Iron
I have started another project handlebars-iron for the Iron web framework.
Break Change Log
No doubt that we will try our best to keep API compatible in each release. But sometime we have to bring in break changes to improve the design when worthy.
ToJsonto avoid unnecessary clone in batch rendering. 90274e7
MIT, of course.