public static void With(TextWriter output, HelperOptions options, dynamic context, params object[] arguments) { if (arguments.Length != 1) { throw new HandlebarsException("{{with}} helper must have exactly one argument"); } if (HandlebarsUtils.IsTruthyOrNonEmpty(arguments[0])) { options.Template(output, arguments[0]); } else { options.Inverse(output, context); } }
public static void Inline(TextWriter output, HelperOptions options, dynamic context, params object[] arguments) { if (arguments.Length != 1) { throw new HandlebarsException("{{*inline}} helper must have exactly one argument"); } //This helper needs the "context" var to be the complete BindingContext as opposed to just the //data { firstName: "todd" }. The full BindingContext is needed for registering the partial templates. //This magic happens in BlockHelperFunctionbinder.VisitBlockHelperExpression if (context as BindingContext == null) { throw new HandlebarsException("{{*inline}} helper must receiving the full BindingContext"); } var key = arguments[0] as string; //Inline partials cannot use the Handlebars.RegisterTemplate method //because it is static and therefore app-wide. To prevent collisions //this helper will add the compiled partial to a dicionary //that is passed around in the context without fear of collisions. context.InlinePartialTemplates.Add(key, options.Template); }