Template scripting

In most of the cases the content that needs to be generated is dynamic, which means that varies in time or needs to be different from user to user.

Webpagebytes CMS is using Freemarker template scripting engine which can be used either in Site pages or in Page Modules. The Freemarker template script allows to mix in the same script multiple type of elements: text, interpolations (similar to variables concept which will be replaced at runtime with specific values), FTL tags (similar to programming if, loops, switch statements) and comments.

An example of freemarker script is the following

<html> 
<body> 
     <h1> Hi ${username} </h1> <#-- ${userName} is an interpolation --> 
     Your order contains the following items: 
    <ul> 
        <#list order as item> <#-- #list is an FTL tag--> 
            <li> ${item.name}, ${item.price}$</li>
        </#list> 
     </ul> 
</body> 
</html>
Each Freemarket script is combined with a “model”, which is a map or key-values containing the data that will be used by the engine script to transform the template script into the final text content.
In the example case the model contains the following data:
-+
 +--username="John"
 +--order
      +--+
         +--name="potatoes"
         +--price=2
      +--+
         +--name="tomatoes"
         +--price=3 
The model contains a map with two keys, username and order. The username type is string meanwhile the order is a list of two objects.
The final text after applying the model will be:
<html> 
<body> 
    <h1> Hi John </h1> 
    Your order contains the following items: 
    <ul> 
    <li> potatoes, 2$</li>
    <li> tomatoes, 3$</li>
    </ul> 
</body> 
</html> 
As can be seen the interpolation ${username} was replaced with John and ${item.name}, ${item.price} took the values from the order list.