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

ifHelper not consuming eol token

Open driden opened this issue 4 years ago • 0 comments

Hello everyone, I'm having an issue when compiling the following template, which I simplified for this report.

String toCompile = "<tr>\n" +
            "                                                <td>\n" +
            "                                                    <!-- content here -->\n" +
            "                                                </td>\n" +
            "                                                {{#if flag }}\n" +
            "                                                <td>\n" +
            "                                                    <!-- td1 content -->\n" +
            "                                                </td>\n" +
            "                                                <td>\n" +
            "                                                    <!-- td2 content -->\n" +
            "                                                </td>\n" +
            "                                                {{/if}}\n" +
            "                                           </tr>";

After compiling, I get 3 TemplateNode:

  1. Text
  2. Block
  3. Text

The last Node, in this case, is starting with a \n character, and that's causing an extra line in my template. I believe said extra line break is there because when compiling the if block, it's not consuming the \n in " {{/if}}\n"

I tried this template over at Try handlebars with the same html

<tr>
    <td>
       <!-- content here -->
    </td> 
    {{#if flag }} 
        <td> 
            <!-- td1 content --> 
        </td> 
        <td> 
            <!-- td2 content --> 
        </td> 
    {{/if}} 
</tr>

And it's not printing that line break, when the flag is set to false.

Thanks in advance

driden avatar Jan 05 '21 15:01 driden