Skip to content

Helper with no parameters not working in a block #820

Description

@mkuchtiak

The following test is not working:

    @Test
    void testHelperInLoop() throws IOException {
        Handlebars handlebars = new Handlebars();
        handlebars.registerHelper("greeting", new Helper<Object>() {
            @Override
            public Object apply(final Object context, final Options options) {
                return "Hello";
            }
        });

        ObjectNode document = JsonNodeFactory.instance.objectNode();
        ArrayNode arrayNode = document.putArray("list");
        arrayNode.addObject();
        arrayNode.addObject();
        Context context = Context.newBuilder(document).push(JsonNodeValueResolver.INSTANCE).build();

        Template template = handlebars.compileInline("{{greeting}}{{#each list as |item|}} '{{greeting true}}'{{/each}}");
        assertThat(template.apply(context)).isEqualTo("Hello 'Hello' 'Hello'");
    }

when the template is applied, the result is:
Hello '' ''
rather than
Hello 'Hello' 'Hello'

The test works, when the template is changed to:
{{greeting}}{{#each list as |item|}} '{{greeting true}}'{{/each}}

So, when no parameters are passed to handlebar helper the helper is not resolved.
This is reproducible only when helper is used in a block (e.g. in #each block)

version: com.github.jknack:handlebars:4.2.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions