FreeMarker
Purpose¶
Apache FreeMarker is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language.
Note
The version of FreeMarker embedded in Platform 6 is configuration compatible with FreeMarker version 2.3.21.
Methods¶
Binding name: p6.fm
process¶
Process a FreeMarker template and data model, returning the result as a String.
Syntax
String p6.fm.process(String templateText, Map model)
Note
Since 6.9.9 i18n
The locale
extracted from the pipeline will be passed to the template (default to EN
).
Date and number format are based on the locale.
The function i18n
is available to retrieve a translation
Example
def model = [
user: 'Jon Doe',
latestProduct: [
name: 'platform6',
url: 'www.amalto.com'
]
]
def html = p6.fm.process(p6.resource.get('FMTEMPLATE'), model)
println html
Resource: FMTEMPLATE
<html>
<head><title>Welcome!</title></head>
<body>
<h1>Welcome ${user}!</h1>
<p>Our latest product: <a href="${latestProduct.url}">${latestProduct.name}</a></p>
</body>
</html>
i18n function
println p6.fm.process('${i18n(\'key\')}', [:])
println p6.fm.process('${i18n(\'key\'), \'fr\'}', [:])