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

In java, equals helper returns java.lang.IllegalArgumentException: "could not find helper: 'eq'"

Open keanerickson-mc opened this issue 3 years ago • 1 comments

For two variables, boolean "skip" and string "name", I'm trying to make this not print anything if "skip" is true

{{# eq skip "false"}} {{name}} {{/eq}} Results in "could not find helper: 'eq'"

I get the same behavior if I use "equals" or "equal" instead of "eq" for the helper

It seems that using "{{#if skip}}{{else}}" is sufficient, but I'd like to understand the eq helper

keanerickson-mc avatar Apr 10 '23 22:04 keanerickson-mc

For two variables, boolean "skip" and string "name", I'm trying to make this not print anything if "skip" is true

{{# eq skip "false"}} {{name}} {{/eq}} Results in "could not find helper: 'eq'"

I get the same behavior if I use "equals" or "equal" instead of "eq" for the helper

It seems that using "{{#if skip}}{{else}}" is sufficient, but I'd like to understand the eq helper

@keanerickson-mc - I had faced the very similar issue, but the below solution worked and template loaded as expected.

Error trace -

IllegalArgumentException: could not find helper: 'eq'] with root cause
java.lang.IllegalArgumentException: could not find helper: 'eq'

You can try with a custom code. Register the necessary class (ConditionalHelpers.eq) in your case.

private final Handlebars handlebars;

handlebars.registerHelper("eq", ConditionalHelpers.eq);

Now consume the above handlerbars in your service -

Template handlerBarTemplate = handlebars.compileInline(template);

  handlerBarTemplate.apply(context, writer);

HarrishSreedhar avatar Aug 11 '23 07:08 HarrishSreedhar