
Basic introduction
FreeMarker is a template engine: a universal tool for generating output text (HTML web pages, emails, configuration files, source code, etc.) based on templates and data to be changed. It is not for end users, but a Java class library, a component that programmers can embed into the products they develop.
Software features
1. Versatility
Able to generate various texts: HTML, XML, RTF, Java source code, etc.
Easy to embed into products: lightweight; no Servlet environment required.
Plug-in template loader: can load templates from any source, such as local files, databases, etc.
The text can be generated as desired: saved to a local file; sent as an Email; sent from a web application back to the web browser.
2. Template language
All commonly used instructions: include, if/elseif/else, loop structures.
Create and change variables in templates.
Complex expressions can be used to specify values almost anywhere.
Named macros, which can have positional parameters and nested content.
Namespaces help you build and maintain reusable macro libraries, or break a large project into modules without worrying about name conflicts.
Output Transformation Block: Convert HTML escaping, compression, syntax highlighting, and more when nested template fragments generate output; you can define your own transformations.
3. Common data model
FreeMarker does not directly reflect to Java objects. Java objects are encapsulated through plug-in objects and displayed in the template as variables.
You can use abstract (interface) methods to represent objects (JavaBeans, XML documents, SQL query result sets, etc.) and tell template developers to use them. method so that it is not bothered by technical details.
4. Prepare for the Web
Structures for handling typical web-related tasks such as HTML escaping are built into the template language.
Can be integrated into the Model2 Web application framework as a replacement for JSP.
Support JSP tag library.
Designed for the MVC pattern: Separate visual design and application logic; Separate page designers and programmers.
5. Intelligent internationalization and localization
Character set intelligence (UNICODE is used internally).
Number formats are localization sensitive.
Date and time formats are localization sensitive.
Non-US character sets can be used for identification (such as variable names).
The same template in many different languages.
6. XML processing capabilities
The <#recurse> and <#visit> directives (version 2.3) are used to recursively traverse the XML tree.
Clear and direct access to the XML object model in templates.















Useful
Useful
Useful