是否可以使用 Pebble 模板引擎从字符串构建模板,而不必提供文件名?
val engine = PebbleEngine.Builder().build()
val writer = StringWriter();
engine.getTemplate("test.html").evaluate(writer);
test.html
例如,我将如何提供以下格式的模板,而不是提供?
val template = "Hello {{world}} - {{count}} - {{tf}}"
我目前在 Pebble 2.2.1
<!-- Pebble -->
<dependency>
<groupId>com.mitchellbosecke</groupId>
<artifactId>pebble</artifactId>
<version>2.2.1</version>
</dependency>
基于我收到的答案的解决方案:
val context = HashMap<String, Any>()
...
val engine = PebbleEngine.Builder().loader(StringLoader()).build();
val writer = StringWriter();
engine.getTemplate(template).evaluate(writer, context);
println(writer.toString());