handlebars.java icon indicating copy to clipboard operation
handlebars.java copied to clipboard

HelperMissing can't replace the functionality of MissingValueResolver

Open pvgoran opened this issue 5 years ago • 1 comments

I'm trying to upgrade from 1.3.0 to 4.1.2. I used MissingValueResolver which is now removed; HelperMissing is suggested as a replacement, but it covers much more cases than MissingValueResolver, and I can't find a good way to detect when HelperMissing is called for a "MissingValueResolver" case.

Specifically, the following two invocations seem to be indistinguishable: {{missing}} and {{missing something}}. MissingValueResolver only caught the first one; however, HelperMissing is called for both of them, with options.tagType=VAR, options.helperName="missing", options.params.length=0. The only visible difference is options.fn.text() which contains either {{missing}} or {{missing something}}; but analyzing the template source is an awkward and unreliable way of finding such a trivial piece of information.

pvgoran avatar Mar 07 '19 11:03 pvgoran

I found out that I can use options.data(Context.PARAM_SIZE) to distinguish these two cases. If it returns zero, it's {{missing}}, otherwise it's {{missing something}}.

But this solution relies on implementation detail, and thus can stop working in the future.

pvgoran avatar Mar 07 '19 12:03 pvgoran