Handlebars Switch Helper

Latest Version Downloads License Docs

This provides a Handlebars {{#switch}} helper to the already incredible handlebars-rust crate.

Links of interest:

Quick Start

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)); ```

Example

Below is an example that renders a different page depending on the user's access level:

```rust extern crate handlebars_switch; extern crate handlebars;

[macrouse] extern crate serdejson;

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" ); } ```