FreeMarker Templates | ||
---|---|---|
Previous | Next | |
API Reference | Groovy Templates |
iKnowBase supports the use of FreeMarker templates. When using FreeMarker templates, you will combine static markup, standard FreeMarker functionality and iKnowBase model objects to create the desired output:
In order to best utilize the FreeMarker technology, you should read the FreeMarker documentation available at http://freemarker.org/docs. Some key features are described below, but this covers only a small subset of the capabilities.
With FreeMarker you can create HTML-based templates that can display data from a Java model. The following figure shows how FreeMarker connects with a template (in this instance an HTML template), and data from a Java object model. This connection generates an HTML output that displays the data in the template.
FreeMarker supports
<#include>
and
<#import>
as mechanisms to reuse templates. With iKnowBase, it is possible to use both of these mechanisms to refer to templates stored inside the iKnowBase repository:
<#include "/urn:iknowbase:template:guid:9E23B9E919E73ECCE040000A18006DD1">
FTL tags are used to call directives. There are two types FTL tags:
<#directive name parameters>
</#directive name>
These tags are similar to the syntaxes in the HTML code and the XML code except for tags that start with #. There are two types of directives: predefined directives and user-defined directives. User defined directives use @ instead of #. For example, <@mydirective parameter>... </@mydirective>.
The format of the parameters depends on the name of the directive.
Property | Description |
---|---|
if, else, elseif |
Syntax:
For example:
For example:
or
For example:
|
If you want to write values directly within the insertion brackets ${ and }, there are some characters that need a specific syntax.
Syntax | Description |
---|---|
\" | Quotation mark (u0022) |
\' | Apostrophe (apostrophe-quote) (u0027) |
\\ | Back slash (u005C) |
\n | Line feed (u000A) |
\r | Carriage return (u000D) |
\t | Horizontal tabulation (tab) (u0009) |
\b | Backspace (u0008) |
\f | Form feed (u000C) |
\l | Less than sign: < |
\g | Greater than sign: > |
\a | Ampersand: & |
\xCode | Character given with its hexadecimal Unicode (UCS) code |
FreeMarker contains a set of built-in functions that you can use directly with variables.
Function | Syntax and Description |
---|---|
html | The ${string?html} variable is coded to the HTML text. For example, the character < becomes <. |
js_string | The ${string?js_string} variable is coded to the JavaScript text. For example, the character ‘ becomes ’'. |
xml | The ${string?xml} variable is coded to the XML text. For example, the character > becomes >. |
url | The ${string?url} variable is coded to the URL text. For example, the character / becomes %2b. |
cap_first | The ${string?cap_first} variable has the initial character capitalized. |
lower_case | The ${string?lower_case} variable gets all the characters decapitalized. |
upper_case | The ${string?upper_case} variable gets all the characters capitalized. |
trim | The ${string?trim} variable peels off all blank characters at the start and end. |
substring | This function uses ${string?substring(from, [to])} tag to take a segment of the variable depending on specified positions. |
replace | The ${string?replace(“this”, “with that”)} variable substitutes the text with other text. |
number | This function uses ${string?number} tag to convert a variable from string to number. |
Function | Syntax and Description |
---|---|
string | This function uses ${number?string} tag to convert a variable from number to text. |
string.number | This function uses ${number?string.number} tag to convert a variable from number to text. |
string.percent | This function uses ${number?string.percent} tag to convert a variable from number to percent text. |
Function | Syntax and Description |
---|---|
string | This function uses ${date?string} tag to convert a variable from date to text. |
string.short | This function uses ${date?string.short} tag to convert a variable from date to a predefined short text. |
string.medium | This function uses ${date?string.medium} tag to convert a variable from date to a predefined medium text. |
string.long | This function uses ${date?string.long} tag to convert a variable from date to a predefined long text. |
string.full | This function uses ${date?string.full} tag to convert a variable from date to a predefined full text. |
Previous | Top | Next |
API Reference | Groovy Templates |