This provides a Handlebars {{#switch}}
helper to
the already incredible handlebars-rust
crate.
Links of interest:
You can easily add the {{#switch}}
helper to a rust Handlebars object using
the Handlebars#register_helper
method:
```rust use handlebars::Handlebars; use handlebars_switch::Handlebars;
let mut handlebars = Handlebars::new(); handlebars.register_helper("switch", Box::new(SwitchHelper)); ```
Below is an example that renders a different page depending on the user's access level:
```rust extern crate handlebars_switch; extern crate handlebars;
use handlebars::Handlebars; use handlebars_switch::SwitchHelper;
fn main() { let mut handlebars = Handlebars::new(); handlebars.register_helper("switch", Box::new(SwitchHelper));
let tpl = "\ {{#switch access}}\ {{#case \"admin\"}}Admin{{/case}}\ {{#default}}User{{/default}}\ {{/switch}}\ ";
asserteq!( handlebars.templaterender(tpl, &json!({"access": "admin"})).unwrap(), "Admin" );
asserteq!( handlebars.templaterender(tpl, &json!({"access": "nobody"})).unwrap(), "User" ); } ```