-
Notifications
You must be signed in to change notification settings - Fork 3
FreeMarker 3
The long-awaited FreeMarker 3 is in a preview phase. You can build it as follows:
git clone https://github.com/freemarker/freemarker3.git
cd freemarker3
ant
Or if you want, here is a pre-built jarfile.
By and large, existing templates should work more or less unchanged, except for a few caveats.
Do note that, as of the latest version, late June 2024, all of the freemarker.*
package structure was moved to freemarker3.*
. This is because I anticipated that some people would want to be able to have "Apache FreeMarker" and FreeMarker 3 running in the same container, so the package change name seemed necessary.
In terms of less superficial changes, note that, by default, templates now use the newer strict variable definition syntax. As a consequence, existing templates simply will not work unless you put the line:
[#ftl legacy_syntax=true]
at the top of them. Though, you can also now write this more tersely as:
#ftl legacy_syntax
An alternative, though, is to turn off the strict vars globally from your Java code, via:
Configuration.getDefaultConfiguration().setLegacySyntax(true);
Another thing to be aware of is that this preview FreeMarker version is somewhat stripped down. For example, older versions of FreeMarker had support for using FreeMarker in conjunction with some alternative JVM based languages, specifically Jython (Python on Java), Rhino (Javascript on Java), and JRuby (Ruby on Java). There is little sign that any of that was being used. So I decided that it was not a good tradeoff to carry that stuff forward when doing all this massive refactoring work. All classes relating to JSP and the servlet API were stripped out. This version of FreeMarker is much more like a pure template engine.
The component that was stripped out that might affect the most people is the built-in XML processing support. This will probably be put back in at a later point. But do note that the only thing I have to go on is whatever feedback I receive, so if the XML support is important to you, by all means, bring it up!
There is a host of built-ins that were added to Apache FreeMarker over the last decade. I have no idea how widely used the newer built-ins are. The ones that seem to be generally useful will get added in, most likely. But, for the moment, it is likely that quite a few existing templates will use built-ins that are not present. If you think a built-in should be added, by all means, just bring it up as an issue here or start a discussion