Created
August 30, 2017 05:24
-
-
Save code-atom/5e301b1d44a15316f2347bb1fc0f7106 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HandlebarHelper | |
{ | |
public static void RegisterHelper() | |
{ | |
RegisterArrayContainsHelper(); | |
} | |
/// <summary> | |
/// {{#arrayContains List<> limit}} | |
/// ... if condition true | |
/// {{else}} | |
/// ... if condition false | |
/// {{/arrayContains}} | |
/// </summary> | |
private static void RegisterArrayContainsHelper() | |
{ | |
Handlebars.RegisterHelper("arrayContains", (writer, helper, context, parameters) => | |
{ | |
if (parameters.Count() < 2) | |
{ | |
writer.Write("arrayContains:Wrong number of arguments"); | |
return; | |
} | |
var array = parameters[0] as IList; | |
var number = Convert.ToInt32(parameters[1]); | |
if (array.Count == number) | |
{ | |
helper.Template(writer, context); | |
} | |
else | |
{ | |
helper.Inverse(writer, context); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment