Skip to content

Instantly share code, notes, and snippets.

@rexm
Created March 30, 2015 22:35
Show Gist options
  • Save rexm/e1a045b9f76a48de642e to your computer and use it in GitHub Desktop.
Save rexm/e1a045b9f76a48de642e to your computer and use it in GitHub Desktop.
var basicTestTemplate = "{{mycustomhelper Person.Address.City}}";
var blockTestTemplate = "{{#mycustomblock Person.FirstName}} Hello world {{/mycustomblock}}";
Handlebars.Handlebars.RegisterHelper (
"mycustomhelper",
(writer, context, arguments) => writer.Write (arguments [0]));
Handlebars.Handlebars.RegisterHelper (
"mycustomblock", (writer, options, context, arguments) => {
options.Template(writer, (object)context);
writer.Write(arguments[0]);
});
var data = new {
Person = new {
FirstName = "Bob",
Address = new {
City = "New York"
}
}
};
var basicTest = Handlebars.Handlebars.Compile (basicTestTemplate);
var blockTest = Handlebars.Handlebars.Compile (blockTestTemplate);
Console.WriteLine (basicTest (data));
Console.WriteLine (blockTest (data));
Console.Read ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment