Question

The Freemarker documentation says:

In practice it means that you can put empty lines between macro definitions and assignments as spacing for better readability, without printing needless empty lines (line breaks) to the output.

When I render the template

Start
<#assign var1 = "Foo"/>

<#assign var2 = "Bar"/>
End

the result is

Start
End

i.e. the newline between the two assignments is stripped. This is what I would expect according to the documentation. However, rendering a slightly modified template

Start
<#assign var1 = "Foo"/>

<#assign var2>
Bar
</#assign>
End

doesn't seem to remove the newline:

Start

End

Is this a bug or am I misinterpreting the documentation? I am using Freemarker 2.3.20.

Was it helpful?

Solution

The documentation means that you can add empty lines between these directives for better readability without adding extra line-break to the output. Also, the line-break after these directives is removed. In you first example, the line-break is at the end of the "Start" line.

That there's no whitespace removal between block-#assign and #assign is a bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top