我正在尝试 FreeMarker,不是用于 Web 应用程序,而是用于在桌面应用程序中生成文本。我想得到没有任何换行符的文本,但是它总是附加一个换行符。例如,这将产生“blah blah\n”
<#if docType=1>
blah blah
<#if docType=2>
more blah
<#/if>
有任何想法吗?将它们全部集中在一条线上是可行的,但很可怕。谢谢。
我正在尝试 FreeMarker,不是用于 Web 应用程序,而是用于在桌面应用程序中生成文本。我想得到没有任何换行符的文本,但是它总是附加一个换行符。例如,这将产生“blah blah\n”
<#if docType=1>
blah blah
<#if docType=2>
more blah
<#/if>
有任何想法吗?将它们全部集中在一条线上是可行的,但很可怕。谢谢。
或许参见White-space handling、ftl和compress指令。但是你不能抑制所有的换行。
另一种解决方案:过滤输出,并将 \n 替换为“”。
我还会看一下t、lt 和 rt 指令。
使用您的示例,
<#if docType=1>
blah blah <#t>
<#if docType=2>
more blah<#t>
<#/if>
应该blah blah more blah
在一条线上生产
<@compress single_line=true>...</@compress>
...这会将压缩标签之间的所有内容输出为一行。