FreeMarker

from Wikipedia, the free encyclopedia
FreeMarker

FreeMarker Logo.png
Basic data

developer Jonathan Revusky, Attila Szegedi, Dániel Dékány ea
Current  version 2.3.30
(March 5, 2020)
operating system platform independent
programming language Java
category Template engine
License Apache license
freemarker.apache.org

FreeMarker is a template engine for the Java platform that replaces placeholders in text files with dynamic content. The most common use is to generate HTML in web applications , but it may not be used. a. also used to generate e-mails , source code and SQL queries. FreeMarker is free software .

FTL FreeMarker Template Language

FreeMarker uses its own simple programming language ( DSL ), which is optimized for use in HTML templates.

The content of variables is output in the form , instructions as noted. Frequently used instruction blocks can be defined as macros and then called up in the form (instructions and macros can have parameters that the "..." should indicate). ${Variable}<#Anweisung …/><@Makro …/>

FTL offers a comparatively wide range of functions. For example, internationalized output of numbers and date values, character substitutions with regular expressions , text for use in JavaScript with masking characters , lists (also) sorting according to subvariables of the elements or addressing DOM nodes in XML documents.

example

Assume that the variables name (a string ) and items (a list of objects with the fields quantity and description ) are available.

The template

Freemarker-Example-1-code.png

then produces the following output:

<p>Einkaufskorb für Max Mustermann:</p>
<ul>
  <li>1 Stk. <b>Bleistift</b>
  <li>2 Stk. <b>Radiergummi</b>
</ul>

Applications

FreeMarker is used in various areas of software technology and is used or used by many programs and frameworks . supported.

  • FreeMarker is used as an alternative to JSP in web applications . The widely used frameworks Struts and Spring offer FreeMarker for this purpose ( Apache Velocity is available as a further alternative ). Since JSP taglibs can be used in FreeMarker, the required taglibs (such as the Struts taglibs) do not have to be dispensed with when switching from JSP to FreeMarker.
  • Struts 2 uses FreeMarker internally for the rendering of JSP, Velocity and FreeMarker tags after the previous project WebWork made a switch from Velocity to FreeMarker.
  • Content management systems like Magnolia use FreeMarker as their template engine.
  • In code generators , source text ( Java , SQL, RTF , PostScript ) is generated dynamically with FreeMarker .
  • the tools of the persistence framework Hibernate use FreeMarker to generate database schemas, SQL and Java code. In 2006 there was a change from Velocity to FreeMarker (partly because of better error handling).
  • NetBeans IDE uses Freemarker internally to fill the template documents with dynamic content in the "New File ..." wizard.

In IDEs such as Eclipse , NetBeans IDE or IntelliJ IDEA , the processing of FreeMarker templates is supported by syntax check, code completion, popup help and the like. supported.

history

FreeMarker 1 was developed by Benjamin Geer and Mike Bayer and released under the LGPL license in January 1999 (still available as "FreeMarker classic").

In 2002 the core was rewritten by Jonathan Revusky ea and released as FreeMarker 2 under the (compared to the LGPL) more liberal BSD license.

literature

There is currently no monograph on FreeMarker, but its configuration and use are described in many manuals for the programs and frameworks that use or support FreeMarker.

  • Donald Brown, Chad Michael Davis, Scott Stanlick Struts 2 in action . Manning (2008) ISBN 978-1933988078 , p. 223ff .: Velocity and FreeMarker as JSP alternatives, p. 336 ff .: Create your own themes by overwriting the internal FreeMarker templates
  • Seth Ladd, Bram Smeets Building Spring 2 Enterprise Applications , Apress (2007) ISBN 978-1590599181 , p. 271 f .: FreeMarker as a view technology for Spring (in addition to JSP, Velocity and XSLT)
  • Jeff Linwood, Dave Minter: Beginning Hibernate . Apress (2010) ISBN 978-1430228509 , S 323f .: Configuration in the Hibernate Tools

Articles in journals :

Web links

Individual evidence

  1. "Download / Maven" menu item on the FreeMarker official website. Retrieved February 25, 2020.
  2. Musachy Barroso ea: Using Freemarker Templates. (No longer available online.) In: Apache Struts 2 Documentation. Archived from the original on August 6, 2010 ; accessed on July 24, 2010 (English). Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.  @1@ 2Template: Webachiv / IABot / struts.apache.org
  3. Rod Johnson ea: Chapter 14. Integrating view technologies. In: The Spring Framework - Reference Documentation. Retrieved July 24, 2010 .
  4. Dániel Dékány ea: Using FreeMarker with servlets. In: FreeMarker Manual. Retrieved July 24, 2010 .
  5. Patrick Lightbody ea: Template Loading. (No longer available online.) In: Apache Struts 2 Documentation. Archived from the original on July 1, 2010 ; accessed on July 24, 2010 (English). Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.  @1@ 2Template: Webachiv / IABot / struts.apache.org
  6. ^ Templating with FreeMarker - a primer. (No longer available online.) In: Magnolia Documentation. Formerly in the original ; accessed on July 24, 2010 (English).  ( Page no longer available , search in web archivesInfo: The link was automatically marked as defective. Please check the link according to the instructions and then remove this notice.@1@ 2Template: Dead Link / documentation.magnolia-cms.com  
  7. Introduction. In: apt-jelly homepage. Retrieved July 24, 2010 .
  8. ^ Max Andersen: A story about FreeMarker and Velocity. In: In Relation To ... February 3, 2006, accessed on July 24, 2010 (English, blog of a Hibernate developer).
  9. FaqFreeMarker. In: NetBeans Wiki. Retrieved July 24, 2010 .
  10. FreeMarker / Velocity. In: IntelliJ IDEA homepage. Retrieved July 24, 2010 .
  11. Dániel Dékány ea: Who We Are. In: FreeMarker Homepage. Retrieved July 24, 2010 .