using System.Collections.Generic;
public static void Main()
Handlebars.RegisterHelper("DateFormatHelper", (writer, context, parameters) => {
var origDate = (DateTime) parameters[0];
var dateFormat = (string) parameters[1];
writer.WriteSafeString("Formatted date: " + origDate.ToString(dateFormat));
Handlebars.RegisterHelper("GetBuyersString", (writer, context, parameters) => {
var contacts = new List<string>();
foreach (var buyer in context.Buyers) {
contacts.Add(buyer.FirstName + " " + buyer.LastName);
writer.WriteSafeString(String.Join(", ", contacts));
Handlebars.RegisterHelper("GetContactsString", (writer, context, parameters) => {
var contacts = new List<string>();
dynamic buyers = parameters[0];
foreach (var buyer in buyers) {
contacts.Add(buyer.FirstName + " " + buyer.LastName);
writer.WriteSafeString(String.Join(", ", contacts));
BirthDate = new DateTime(1974, 8, 23)
BirthDate = new DateTime(1950, 6, 1)
BirthDate = new DateTime(2000, 2, 14)
var rawTemplateDateFormatExample = @"{{Buyers.1.LastName}}, {{Buyers.1.FirstName}} - {{DateFormatHelper Buyers.1.BirthDate ""dddd, dd MMMM yyy""}}";
var rawTemplateShowBuyersExample = @"Buyers: {{GetBuyersString Buyers}}";
var rawTemplateGetContactsStringExample = @"Contacts: {{GetContactsString Buyers}}";
var rawTemplateLoopInTemplateExample =
{{this.FirstName}} {{this.LastName}}
var templateDateFormatExample = Handlebars.Compile(rawTemplateDateFormatExample);
var templateGetBuyersExample = Handlebars.Compile(rawTemplateShowBuyersExample);
var templateGetContactsExample = Handlebars.Compile(rawTemplateGetContactsStringExample);
var templateLoopInTemplateExample = Handlebars.Compile(rawTemplateLoopInTemplateExample);
var dateFormatExample = templateDateFormatExample(data);
var getBuyersExample = templateGetBuyersExample(data);
var getContactsExample = templateGetContactsExample(data);
var templateLoopExample = templateLoopInTemplateExample(data);
Console.WriteLine("Date Format Example:\n{0}", dateFormatExample);
Console.WriteLine("Get Buyers Example:\n{0}", getBuyersExample);
Console.WriteLine("Get Contacts Example:\n{0}", getContactsExample);
Console.WriteLine("Template Loop Example:\n{0}", templateLoopExample);