handlebars.java
handlebars.java copied to clipboard
HelperMissing can't replace the functionality of MissingValueResolver
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.
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.