Is it possible for Handlebars.Net to report errors/warnings for missing properties?

432 views Asked by At

Imagine that I have a template that requests {{Foo}} but that property does not exist on the given model. Can Handlebars.Net be configured to report this problem to me? To me it looks like it just silently inserts an empty string and proceeds.

1

There are 1 answers

0
default.kramer On BEST ANSWER

The answer is yes:

var config = new HandlebarsConfiguration()
{
    ThrowOnUnresolvedBindingExpression = true,
};
var handlebars = HandlebarsDotNet.Handlebars.Create(config);
var template = handlebars.Compile("Hello {{MissingProperty}}");
template(new object());

This will throw an exception telling you that MissingProperty was missing.

There is also the UnresolvedBindingFormatter which can be used if you don't want to throw an exception.

Related: The discussion on https://github.com/Handlebars-Net/Handlebars.Net/issues/143