What is Apache FreeMarker™?

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 (not a full-blown programming language like PHP). Usually, a general-purpose programming language (like Java) is used to prepare the data (issue database queries, do business calculations). Then, Apache FreeMarker displays that prepared data using templates. In the template you are focusing on how to present the data, and outside the template you are focusing on what data to present.

Figure

This approach is often referred to as the MVC (Model View Controller) pattern, and is particularly popular for dynamic web pages. It helps in separating web page designers (HTML authors) from developers (Java programmers usually). Designers won't face complicated logic in templates, and can change the appearance of a page without programmers having to change or recompile code.

While FreeMarker was originally created for generating HTML pages in MVC web application frameworks, it isn't bound to servlets or HTML or anything web-related. It's used in non-web application environments as well.

See the Manual for more details...

Features

A few highlights of FreeMarker:

  • Powerful template language: Conditional blocks, iterations, assignments, string and arithmetic operations and formatting, macros and functions, including other templates, escaping by default (optional), and many more

  • Multipurpose and lightweight: Zero dependencies, any output format, can load templates from any place (pluggable), many configuration options

  • Internationalization/localization-aware: Locale sensitive number and date/time formatting, localized template variations.

  • XML processing capabilities: Drop XML DOM-s into the data-model and traverse them, or even process them declaratively

  • Versatile data-model: Java objects are exposed to the template as a tree of variables through pluggable adapters, which decides how the template sees them.

License

Apache FreeMarker is Free software, licensed under the Apache License, Version 2.0. See the license here....

Note that the project is owned by the Apache Software Foundation since 2.3.24-pre01 (2015-09-02). Earlier releases, such as 2.3.23, has a different copyright owner.