【发布时间】:2015-08-02 10:44:49
【问题描述】:
我希望 Freemarker 在调用我的宏后保留换行符。
我已经搞砸了关闭标签<@test></@test> 没有任何区别。我也尝试过在指令中使用body,但那是空的。
也许我可以在标签之后访问模板内容,如果那是换行符,那么我可以打印它。但这似乎有点乱。
我的模板包含:
<@test/> <@test/>
<@test/>
<@test/>
什么是印刷品:
test test
test
test
但我想打印:
test test
test
test
这就是我定义指令的方式:
public class TestMacro implements TemplateDirectiveModel {
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
env.getOut().append("test");
}
}
这就是我将它添加到配置中的方式:
Configuration config = configurer.createConfiguration();
config.setSharedVariable("test", new TestMacro());
【问题讨论】:
标签: macros whitespace freemarker