Developer(s) | Jonathan Revusky, Attila Szegedi, Dániel Dékány, and others |
---|---|
Stable release | 2.3.18 / May 21, 2011 |
Preview release | 2.4 Preview 1 / July 16, 2008 |
Development status | Active |
Written in | Java |
Operating system | Cross-platform |
Type | Template Engine |
License | BSD-like License |
Website | freemarker.org |
FreeMarker is a Java-based template engine focusing on the MVC software architecture. Although it's mostly used for Servlet-based Web Application development, it can be used for any other kind of text output, such as generating CSS, Java source code, etc. Unlike JSP, it is not dependent on the Servlet architecture or on HTTP. Thus it can be used for non-Web tasks as well. FreeMarker is Free software.
Contents |
FreeMarker has a somewhat hectic history, caused by paradigm shifts and other significant changes at multiple occasions. FreeMarker 1 (now known as FreeMarker Classic, a separate project) was originally written by Benjamin Geer and Mike Bayer. From 2002, the new project lead was Jonathan Revusky, who released FreeMarker 2, which started a sequence of several substantial changes. The main aim of the changes was to make the template language more strict, i.e., to detect as many of the typos and other typical mistakes as early as possible. Also, the automatic object wrapping was introduced, along with the gradual advancement of the type system of the template language. Last but not least, the language has gained a lot of power-user features, such as more powerful macro programming capabilities. The language didn't reach a reasonably settled state until version 2.3, released in 2004 Q3. Since then, the product has remained fully backward compatible, however some not entirely backward compatible changes are still expected in 2.4, which was tentatively scheduled to be released in 2008 Q4 but is still actively being developed.
The following template:
<html> <body> <p>Hello ${name}! You have the following messages: <#list messages as m> <p><b>${m.from}:</b> ${m.body}</p> </#list> </body> </html>
processed by FreeMarker will produce something like:
<html> <body> <p>Hello Joe! You have the following messages: <p><b>Tim:</b> Please don't forget to bring the conference papers!</p> <p><b>Cindy:</b> Can you give me visit afternoon?</p> <p><b>Richard:</b> Man, this time don't forget the papers!</p> </body> </html>
Variables like "name" and "messages" are coming from outside the template, and thus the template author has to deal with the presentation issues only. The template remains the same regardless if these variables are coming from a database or from a cookie or calculated on whatever other ways. Also the exact Java API (and hence the class) of the values can be hidden in FreeMarker using a technique called object wrapping. For example, "messages" seems to be a list or array of Java beans that have "from" and "body" properties, but it might be as well something very different, and the template is not affected (as long as a proper object wrapper is used).