Does layout dialect work with TemplateMode.TEXT?
GGuedesAB opened this issue · comments
When I request a template to be processed, it does not decorate the template it should decorate.
Am I missing something? I read https://ultraq.github.io/thymeleaf-layout-dialect/ and https://www.thymeleaf.org/doc/articles/layouts.html and could not find any information about the support of TemplateMode.TEXT.
Here is my testcase:
Thymeleaf v3.0.15
thymeleaf-layout-dialect v3.1.0
JDK v1.8.0_65:
layout.txt:
List of contents:
[# layout:fragment="list" /]
contents.txt:
[# layout:decorate="~{layout}"]
[# layout:fragment="list"]
[# th:each="element: ${myList}"][[${element}]], [/]
[/]
[/]
TemplateGen.java:
public class TemplateGen {
public static void main(String[] args) {
FileTemplateResolver templateResolver = new FileTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.TEXT);
templateResolver.setPrefix("templates/");
templateResolver.setSuffix(".txt");
final TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
templateEngine.addDialect(new LayoutDialect(null, false));
List<String> myList = Arrays.asList("Pepper", "Milk", "Tea");
final Context ctx = new Context();
ctx.setVariable("myList", myList);
Writer output = new OutputStreamWriter(System.out);
templateEngine.process("contents", ctx, output);
}
}
Output:
Pepper, Milk, Tea,
Unfortunately the layout dialect does not support the TEXT template mode, only HTML and XML. It could be something to add - I think you're the first to ever ask about it!
Would also be interested in this