'I want to use Thymeleaf same as handlebars or freemarker
I wanted to use Thymeleaf as simple string resolver like handlebars and did some code presuming it will work
pom.xml
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.15.RELEASE</version>
</dependency>
code
Map<String, Object> data = new HashMap<String, Object>();
data.put("name", "dickens");
data.put("age", "100");
TemplateEngine en = new TemplateEngine();
Context c = new Context(Locale.ENGLISH, data);
String p = en.process("Hello ${name} your age is ${age}", c);
System.out.println(p);
The output I am getting is
Hello ${name} your age is ${age}
I am expecting it will print Hello dickens your age is 100
I cannot to put Hello [[${name}]] your age is [[${age}]]
that will be a major change everywhere, Is there any flag that I can enable string inline all places?
Solution 1:[1]
You need to create a Resolver:
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.StringTemplateResolver;
...
StringTemplateResolver resolver = new StringTemplateResolver();
resolver.setTemplateMode(TemplateMode.TEXT);
...
en.setTemplateResolver(resolver);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
