开发者

Ignoring all line feeds in a FreeMarker template

开发者 https://www.devze.com 2022-12-30 09:09 出处:网络
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 appen

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号