Scripting With Freemarker

Herogi supports Freemarker for generating custom dynamic action parameters. You can create templates that has dynamic parameters to be changed according to event and session data while action is processed.

Freemarker is a powerful template language that you can use assignments, conditional blocks, string and arithmetic operations and formatting, macros and functions, and many more features. Here you can find some of them detailed;


You can define variables and assign values to them. Usage of assignment operator is like that;

<#assign name1=value1 name2=value2 … nameN=valueN>

For an email action, body parameter can be written like;

    <#assign username="${}"+" "+"${event.surname.value()}">


        Hello ${username},
        Welcome to <a href="">Herogi</a>


There is a variable defined as username and it is assigned by concatenating name and surname values of event. For an event that has a name parameter like Jenn and surname parameter like Brown, this template will be;


        Hello Jenn Brown,
        Welcome to <a href="">Herogi</a>



You can use if, elseif and else to create different results according to different conditions.

Usage of if, elseif and else keywords are like that;

<#if condition >
<#elseif condition2 >
<#elseif condition3 >

elseif and else are optional, you can use if without them.

Here is an example;


      Hello <#if ${event.gender.value()} == "male">Mr.<#else>Mrs.</#if> ${event.surname.value()},
      Welcome to <a href="">Herogi</a>


If the gender parameter is male and surname parameter is Brown then this template will be;


      Hello Mr. Brown
      Welcome to <a href="">Herogi</a>


Arithmetic Operations

You can use arithmetic operations to make calculations.

Here are some examples;

    <#assign averageAmount=(amount1+amount2)/2>
    <#assign profit=salePrice-cost>


You can use functions to simplfy your work.

Usage of a function is like that;

<#function name param1 param2paramN >
<#return returnValue >

Here is an example of a function that concatenates name and surname and returns concatenated string;

    <#function concat name surname>
        <#return name+" "+surname>

If you call concat function like;

    ${concat("Jenn", "Brown")}

then it returns

    Jenn Brown


You can use list to iterate in a loop.

Usage of a list is like that;

<#list sequence as item ></#list>

Here is an example;

    <#list names as name>

Assuming names contains the [‘Jenn’, ‘Jack’, ‘Smith’] sequence, output of this template will be;


Parse string as json data

You can parse string as json data by using eval keyword and use parsed datas in your template.

Here is an example of parsing string as json data and usage of parsed datas;

    <#assign personDatas = person?eval>

    <#list person?keys as k>
      ${k} => ${personDatas[k]}

Assuming person as a json data like {name “:” Jenn “, “ surname “:” Brown “, “ age “: 25 }, output of this template will be;

    name => Jenn
    surname => Brown
    age => 25


You can add comments to your template to make it more readeble.

Here is an example;

    <#-- Enter your comment here -->

More about Freemarker

Freemarker has much more features than shown here, so you can visit Freemarker’s website by clicking here to discover more.