Scenario
Handlebars.js
Template
{{^test input}}empty{{else}}not empty{{/test}}
Helper
Handlebars.registerHelper("test", function(conditional, options) {
if (conditional) {
return options.fn(conditional);
} else {
return options.inverse(conditional);
}
});
Input & result
{ "input": 1 } // Result: not empty
{ "input": 0 } // Result: empty
Handlebars.Net
[Fact]
public void BlockHelperWithInversion()
{
string source = @"{{^test input}}empty{{else}}not empty{{/test}}";
var handlebars = Handlebars.Create();
handlebars.RegisterHelper("test", (output, options, context, arguments) =>
{
if (HandlebarsUtils.IsTruthy(arguments[0]))
{
options.Template(output, context);
}
else
{
options.Inverse(output, context);
}
});
var template = handlebars.Compile(source);
Assert.Equal("empty", template(null));
Assert.Equal("empty", template(new { otherInput = 1 }));
Assert.Equal("not empty", template(new { input = 1 }));
}
Actual result
- ❌
^test detected as HandlebarsHelper instead of HandlebarsBlockHelper
- ❌
^test tried to be late-bounded
- ❌
Template references a helper that is not registered. Could not find helper '^test' exception thrown
Expected result
- matches to Handlebars.js behaviour.
Scenario
Handlebars.js
Template
Helper
Input & result
Handlebars.Net
Actual result
^testdetected asHandlebarsHelperinstead ofHandlebarsBlockHelper^testtried to be late-boundedTemplate references a helper that is not registered. Could not find helper '^test'exception thrownExpected result