This page attempts to give you few highlights of FreeMarker features.
- Can be used to generate any kind of text: HTML, XML, RTF, Java source code, etc.
- Easy to embed into your product: Lightweight. Does not require servlet environment (does not depend on javax.servlet classes).
- Pluggable template loader: you can load templates from any sources; local files, database, etc.
- You can do whatever you want with the generated text: store it in a local file, send it as e-mail, send it back to a Web browser from a Web application, etc.
Powerful template language
- All usual directives: include, if/elseif/else, loop constructs.
- Creating and changing variables in templates.
- Can use complex expressions to specify values almost everywhere.
- String operations: concatenation, sub-string, uppercase, capitalize, escaping, etc.
- Decimal precision arithmetic calculations
- Boolean arithmetic
- Reading array and associative array elements
- Array and associative array literals
- You can add your own functions (methods) for special calculations.
- Macros with named and positional parameters and with nested content (body). For example:
<@myMacro color="red" width=2>...</@myMacro>
- Name-spaces to help build and maintain reusable macro libraries or to divide big projects into separated modules, without worrying about name clashes.
- Output transformation blocks. Do transformations as HTML-escaping, compression, syntax-highlight etc. on the output generated by the nested template fragment. You can define your own transformations.
Versatile data model
FreeMarker does not work through direct reflection on Java objects; the Java objects are exposed to the template as variables through pluggable object wrappers. Thus, you can show the objects (Java beans, XML documents, SQL query result sets, etc.) in an abstract, tailored way for the template authors, without bothering them with technical details.
- Built-in constructs in the template language to handle typical Web related tasks like HTML-escaping.
- Can be integrated with "Model 2" Web application frameworks out-of-the-box as JSP replacement.
- Supports JSP taglibs, up to JSP 2.1 currently, except that the JSP 2 "tag files" (i.e., when custom tags are implemented in JSP language rather than as Java classes) are not supported.
- Designed for MVC pattern: separate visual design from application logic, separate page designers from programmers.
- Charset aware (uses UNICODE internally).
- Locale sensitive number formatting.
- Locale sensitive date and time formatting.
- Non-US characters can be used in identifiers (as variable names).
- Multiple variations of the same template for different languages.
Powerful XML Processing Capabilities
- <#recurse> and <#visit> directives (new in version 2.3) for recursively walking an XML tree
- Clean, intuitive XML object model accessible from template.
Comparing with other products
You might also be interested
FreeMarker from Apache Velocity.
FreeMarker 2.3 often can be used as an alternative to XSLT. You can read our comparison here.