TemplateEngines
Overview
Module
- package:
org.eclipse.dirigible.sdk.template - source: template/TemplateEngines.java
Renders a template against a JSON parameter document. Three engines are available:
- Mustache — logic-less; perfect for emails and HTML fragments.
- Velocity — Apache Velocity with the platform's default tool set.
- JavaScript — evaluates
${expr}fragments through GraalJS for the full power of script expressions inside the template.
generate(template, parametersJson) picks the default engine (Mustache); the named variants are for explicit choice. The five-argument generate overload lets you change the marker pair (the Mustache defaults are double curly braces) — useful when the template body itself contains the delimiter characters.
Key Features:
- Three engines — pick the one that suits the template style.
- Custom markers — override start / end delimiters per call.
- JSON parameter document — consistent JSON shape across the platform.
Example Usage:
java
import org.eclipse.dirigible.sdk.template.TemplateEngines;
String out = TemplateEngines.generate(
"Hello, {{name}}!",
"{\"name\":\"Alice\"}");
String html = TemplateEngines.generateMustache(
"<p>Order {{orderId}} total {{amount}}</p>",
"{\"orderId\":\"42\",\"amount\":\"1299.00\"}");Methods
generate()
Renders a template using the default (Mustache) engine.
javapublic static String generate(String template, String parametersJson) throws IOException;
Parameter Type Description templateStringTemplate body. parametersJsonStringJSON document supplying the substitution values. Returns
- Type:
String- Description: Rendered output.
generateMustache()
Renders explicitly with the Mustache engine.
javapublic static String generateMustache(String template, String parametersJson) throws IOException;
generateVelocity()
Renders with Apache Velocity.
javapublic static String generateVelocity(String template, String parametersJson) throws IOException;
generateJavascript()
Renders with the JavaScript engine — ${expr} fragments are evaluated through GraalJS.
javapublic static String generateJavascript(String template, String parametersJson) throws IOException;
generate() — custom markers
Renders with custom delimiter markers (defaults vary per engine).
javapublic static String generate(String location, String template, String parametersJson, String startMarker, String endMarker) throws IOException;
Parameter Type Description locationStringOptional source label used in error messages. templateStringTemplate body. parametersJsonStringJSON document with substitution values. startMarkerStringOpening delimiter (e.g. <%).endMarkerStringClosing delimiter (e.g. %>).