Can we use StringTemplateResolver to populate a string template with Icontext. If so how we can do? TemplateProcessingParameters and IResourceResolver is removed from Thymeleaf 3. Any working example would greatly help?
I have followed this example and it works great in Thymeleaf 2
Is there a way to make Spring Thymeleaf process a string template?
I didnt see any reference any migration guide as well.
I think I found a solution. If anybody has better answer please let me know. I did a small mistake earlier. Hope this helps.
private TemplateEngine templateEngine;
private TemplateEngine getTemplateEngine() {
if(null == templateEngine){
templateEngine = new TemplateEngine();
StringTemplateResolver templateResolver =new StringTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateEngine.setTemplateResolver(templateResolver);
}
return templateEngine;
}
public String getTemplateFromMap(String htmlContent, Map<String, String> dynamicAttibutesMap) {
templateEngine = getTemplateEngine();
String template = null;
final Context ctx = new Context(new Locale(TEMPLATE_LOCAL));
if (!CollectionUtils.isEmpty(emailAttibutesMap)) {
dynamicAttibutesMap.forEach((k,v)->ctx.setVariable(k, v));
}
if (null != templateEngine) {
template = templateEngine.process(htmlContent, ctx);
}
return 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