A simple, small but powerful template engine based loosely on the FreeMarker syntax. FreshMarker is implemented in Java 17 (Java 21 since version 1.0.0) and supports the java.time
API and Records.
You can find a detailed description of all Freshmarker features in the manual.
The release notes contain changes to the template engine since version 1.4.6.
Some in-depth articles on Freshmarker can be found on schegge.de.
Simple Example
Configuration configuration = new Configuration();
Template template = configuration.builder().getTemplate("test", "temporal=${temporal}, path=${path.size}");
String result = template.process(Map.of("temporal", LocalTime.of(12, 30), "path", Path.of("text.pdf")));
List with loop Variable
Template template = configuration.builder().getTemplate("ancestors-loop",
"""
<#list ancestors as ancestor with loop>
${loop?index}. ${ancestor.givenname} ${ancestor.surename}
</#list>
""");
String result = template.process(Map.of("ancestors", ancestorService.ancestorsByFamily("Kaiser")));
Partial reduction of a Template
Template template = configuration.builder().getTemplate("ancestors-loop",
"""
<h1>$title</h1>
<#list ancestors as ancestor with loop>
${loop?index}. ${ancestor.givenname} ${ancestor.surename}
</#list>
""");
Template reduced = template.reduce("title", "Genealogy List");
String result = reduced.process(Map.of("ancestors", ancestorService.ancestorsByFamily("Kaiser")));