Jump to content

FreeMarker

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 206.55.101.94 (talk) at 14:14, 13 April 2016 (Added a closing paragraph tag. Maybe I got it right, or maybe it belongs at the end of the "Hello" line.. but given the indentation I think this was what was intended.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

FreeMarker
Developer(s)Jonathan Revusky, Attila Szegedi, Dániel Dékány, and others
Stable release
2.3.24 / March 28, 2016 (2016-03-28)
Repository
Written inJava
Operating systemCross-platform
TypeTemplate Engine
LicenseApache License 2.0
Websitefreemarker.org

FreeMarker is a Java-based Template Engine, originally focusing on dynamic web page generation with MVC software architecture. However, it's a general purpose template engine, with no dependency on servlets or HTTP or HTML, and so it's often used for generating source code, configuration files or e-mails. FreeMarker is Free software.

History

FreeMarker had a somewhat hectic history until about 2004, caused by paradigm shifts and other significant changes on 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 goal 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 possible. Also, automatic object wrapping was introduced, along with gradual advancement of the type system of the template language. The language has gained many power-user features, such as more powerful macro programming capabilities and namespaces. The language has reached a quite settled state with version 2.3, released in 2004 Q3. As of 2016, the product has remained backward compatible. No significant backward incompatible changes are expected in the FreeMarker 2 series in the future.

In late 2015, FreeMarker was granted to the Apache Software Foundation, where it has entered the Apache Incubator (means, it tries to grow to a fully accepted Apache project).

Example

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>
</p>
</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 a visit this afternoon?</p>
  <p><b>Richard:</b> Don't forget the papers this time!</p>
</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 as well be something very different, and the template is not affected (as long as a proper object wrapper is used).

See also