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

Whitespace issue when using else if

Open wolfjazz opened this issue 4 years ago • 4 comments

Hi,

When I run the following example (please note the indentation of the inner block and that an else-if is used)

{{#if test}}
    {{#if test.a}}
    hihi
    {{else if test.b}}
    hoho
    {{else}}
    huhu
    {{/if}}
    hehe
{{/if}}

the result I get for { test: { c: true, }, } is that hehe is intended twice:

    huhu
        hehe

However, when I try the same example with a nested if-else block instead the else if,

{{#if test}}
    {{#if test.a}}
    hihi
    {{else}}
    {{#if test.b}}
    hoho
    {{else}}
    huhu
    {{/if}}
    {{/if}}
    hehe
{{/if}}

I get the result I would expect for both cases, namely that both words are indented just once:

    huhu
    hehe

You can test that for yourself in the handlebars playground.

So I think I've found a Handlebars bug here. Or am I just doing something wrong?

wolfjazz avatar Oct 01 '20 15:10 wolfjazz

I'm facing the same issue in a different context.

Akazm avatar Oct 02 '21 07:10 Akazm

I am also facing this problem in my project. Does anyone have any idea on how to fix this bug?

mickprev avatar Apr 14 '22 12:04 mickprev

I am also facing this problem in my project. Does anyone have any idea on how to fix this bug?

The only solution that worked for me was not using else if at all but using nested if‘s as can be seen in my second example above.

wolfjazz avatar Apr 14 '22 20:04 wolfjazz

I am also facing this problem in my project. Does anyone have any idea on how to fix this bug?

The only solution that worked for me was not using else if at all but using nested if‘s as can be seen in my second example above.

Yes it's a shame to have to use this syntax to fix the bug. I would like to understand where the problem comes from :s

mickprev avatar Apr 15 '22 06:04 mickprev