Ronnie
Ronnie

Reputation: 5043

Requirejs Handlebar plugin empty lines

I do not know if this is specific to the requirejs handlebar plugin but when I have a template like :

<h1>abc</h1>
{{#if testcondition1}}
<h1>def</h1>
{{/if}}
{{#if testcondition2}}
<h1>ghi</h1>
{{/if}}
<h1>xyz</h1>

I get a empty line if one condition is false. so like:

<h1>abc</h1>

<h1>ghi</h1>
<h1>xyz</h1>

and not

<h1>abc</h1>
<h1>ghi</h1>
<h1>xyz</h1>

Is this the expected behavior? I'd like to get no lines without recurring to string manipulation after the template compilation. I know that lines get ignored in html but this can be really annoying especially in loops.

Upvotes: 0

Views: 194

Answers (1)

Mike Precup
Mike Precup

Reputation: 4218

If you look at the newline placements in your code:

<h1>abc</h1>\n
{{#if testcondition1}}\n
<h1>def</h1>\n
{{/if}}\n
{{#if testcondition2}}\n
<h1>ghi</h1>\n
{{/if}}\n
<h1>xyz</h1>\n

You can see that if the first condition is false, the code without the skipped branch is:

<h1>abc</h1>\n
\n
{{#if testcondition2}}\n
<h1>ghi</h1>\n
{{/if}}\n
<h1>xyz</h1>\n

which gives you two newlines in a row.

Upvotes: 1

Related Questions