I have the template saved as a string somewhere and I want to create the mustache with that. How can I do this? Or is it doable?
Here is the method I found:
private String renderMustacheContent() throws IOException {
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache;
if (type.getTemplate().trim().isEmpty()) {
String emailContent = genCpuEmailContent(cmsKey);
mustache = mf.compile(new StringReader(emailContent), "cpu.template.email");
} else {
mustache = mf.compile(type.getTemplate());
}
StringWriter writer = new StringWriter();
mustache.execute(writer, values).flush();
return writer.toString();
}
So, basically when you just want to render the email from a String template rather than a file, just create the new StringReader with the template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With