Apache FreeMarker

Apache FreeMarker is a popular template engine that can generate a text output based on the template and variable data. Apache FreeMarker templates use a custom programming language named FreeMarker Template Language (FTL), which is used to write programming constructs in presentation views.

A controller is used to prepare the data required, which is then passed on to the template in order to render the presentation views. Apache FreeMarker focuses on how to present the data that is sent to it in an aesthetically pleasing manner. 

Apache FreeMarker adheres to the MVC pattern and templates can be developed by UI engineers, while the data required to render the final presentation views can be computed in the backend and sent by developers independently and transparently. 

Some features of Apache FreeMarker are as follows:

  • FTL has common programming syntaxes for conditional blocks, iterations, assignments, string, arithmetic operations, and so on
  • It is lightweight and flexible
  • It has internationalization (i18n support)

A snippet of this syntax is as follows:

<!DOCTYPE HTML>
<html>
...
<body>
<#if message??>
<p>${message}</p>
</#if>
</body>
</html>

The preceding Apache FreeMarker code basically checks if a variable by the name message is present, and if so, displays it inside of a paragraph tag. More details on Apache FreeMarker can be referenced from the following documentation:

https://freemarker.apache.org/docs/dgui_quickstart_basics.html.

In order to use Apache FreeMarker, the following Maven starter dependency needs to be included:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>

Adding the preceding Maven dependency will import all the required dependencies for Apache FreeMarker to be used in the web application successfully. The following sections will describe how to sketch design the Bloggest application and then implement it using Apache FreeMarker.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.254