FreeMarker

Last updated
Apache FreeMarker
Developer(s) Jonathan Revusky, Attila Szegedi, Dániel Dékány, and others
Initial release2000
Stable release
2.3.32 / January 14, 2023;14 months ago (2023-01-14)
Repository github.com/apache/freemarker
Written in Java
Operating system Cross-platform
Type Template Engine
License Apache License 2.0
Website freemarker.apache.org

Apache FreeMarker is a free Java-based template engine, originally focusing on dynamic web page generation with MVC software architecture. It can now generate text based on templates and changing data. [1] It has no dependency on servlets or HTTP or HTML. [2]

Contents

It is often used for generating source code, configuration files or e-mails.

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 2022, 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, and in 2018-03-21 it has become 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 in 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 JavaBeans 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

Related Research Articles

<span class="mw-page-title-main">JavaScript</span> High-level programming language

JavaScript, often abbreviated as JS, is a programming language and core technology of the Web, alongside HTML and CSS. 99% of websites use JavaScript on the client side for webpage behavior.

A "Hello, World!" program is generally a simple computer program which outputs to the screen a message similar to "Hello, World!" while ignoring any user input. A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. A "Hello, World!" program is often the first written by a student of a new programming language, but such a program can also be used as a sanity check to ensure that the computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.

Jakarta Server Pages is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java programming language.

<span class="mw-page-title-main">Apache Groovy</span> Programming language

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.

ColdFusion Markup Language, more commonly known as CFML, is a scripting language for web development that runs on the Java virtual machine (JVM), the .NET framework, and Google App Engine. Several commercial and free and open-source software implementations of CFML engines are available, including Adobe ColdFusion, Lucee, New Atlanta BlueDragon, Railo, Open BlueDragon, and other CFML server engines.

Apache Wicket, commonly referred to as Wicket, is a component-based web application framework for the Java programming language conceptually similar to JavaServer Faces and Tapestry. It was originally written by Jonathan Locke in April 2004. Version 1.0 was released in June 2005. It graduated into an Apache top-level project in June 2007.

<span class="mw-page-title-main">Apache Tapestry</span> Open-source web application framework

Apache Tapestry is an open-source component-oriented Java web application framework conceptually similar to JavaServer Faces and Apache Wicket. Tapestry was created by Howard Lewis Ship, and was adopted by the Apache Software Foundation as a top-level project in 2006.

CherryPy is an object-oriented web application framework using the Python programming language. It is designed for rapid development of web applications by wrapping the HTTP protocol but stays at a low level and does not offer much more than what is defined in RFC 7231.

Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application.

<span class="mw-page-title-main">TurboGears</span>

TurboGears is a Python web application framework consisting of several WSGI components such as WebOb, SQLAlchemy, Kajiki template language and Repoze.

<span class="mw-page-title-main">Jinja (template engine)</span> Template engine for the Python programming language associated with the Flask framework

Jinja is a web template engine for the Python programming language. It was created by Armin Ronacher and is licensed under a BSD License. Jinja is similar to the Django template engine but provides Python-like expressions while ensuring that the templates are evaluated in a sandbox. It is a text-based template language and thus can be used to generate any markup as well as source code.

Haml is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives you the flexibility to have some dynamic content in HTML. Similar to other template systems like eRuby, Haml also embeds some code that gets executed during runtime and generates HTML code in order to provide some dynamic content. In order to run Haml code, files need to have a .haml extension. These files are similar to .erb or .eRuby files, which also help embed Ruby code while developing a web application.

Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required.

In computing, Facelets is an open-source Web template system under the Apache license and the default view handler technology for Jakarta Faces. The language requires valid input XML documents to work. Facelets supports all of the JSF UI components and focuses completely on building the JSF component tree, reflecting the view for a JSF application.

Apache Click is a page and component oriented web application framework for the Java language and is built on top of the Java Servlet API.

Java view technologies and frameworks are web-based software libraries that provide the user interface, or "view-layer", of Java web applications. Such application frameworks are used for defining web pages and handling the HTTP requests (clicks) generated by those web pages. As a sub-category of web frameworks, view-layer frameworks often overlap to varying degrees with web frameworks that provide other functionality for Java web applications.

<span class="mw-page-title-main">Google Closure Tools</span> JavaScript developer toolkit

Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. As of 2023, the project had over 230K LOCs not counting the embedded Mozilla Rhino compiler.

Thymeleaf is a Java XML/XHTML/HTML5 template engine that can work both in web (servlet-based) and non-web environments. It is better suited for serving XHTML/HTML5 at the view layer of MVC-based web applications, but it can process any XML file even in offline environments. It provides full Spring Framework integration.

<span class="mw-page-title-main">Yesod (web framework)</span>

Yesod is a web framework based on the programming language Haskell for productive development of type-safe, representational state transfer (REST) model based, high performance web applications, developed by Michael Snoyman, et al. It is free and open-source software released under an MIT License.

References

  1. Cardoza, Christina (2017-03-27). "Apache Calcite, FreeMarker, Gora, Phoenix, and Solr updated". SD Times. Retrieved 2024-02-05.
  2. Mittapalli, Jishnu Saurav; Arthur, Menaka Pushpa (2021). "Survey on Template Engines in Java". ITM Web of Conferences. EDP Sciences. 37: 01007. doi:10.1051/itmconf/20213701007. ISSN   2271-2097.