Ignoring all line feeds in a FreeMarker template
I'm trying out FreeMarker,开发者_StackOverflow社区 not for a web application but to generate text within a desktop application. I'd like to get the text without any linefeeds, however it always appends a linefeed. For example, this would produce "blah blah\n"
<#if docType=1>
blah blah
<#if docType=2>
more blah
<#/if>
Any ideas? Bunching it all into one line works, but is horrible. Thanks.
See perhaps White-space handling, ftl and compress directives. But you can't suppress all linefeeds.
Another solution : filter the output, and replace \n by " ".
I would also take a look at t,lt, and rt directives.
Using your example,
<#if docType=1>
blah blah <#t>
<#if docType=2>
more blah<#t>
<#/if>
Should produce blah blah more blah
on a single line
<@compress single_line=true>...</@compress>
...this will output everything in between the compress tag as one line.
精彩评论