Basic Usage

Variables

You can use variables to store information such as text and numbers, but also as a reference to other structures such as a list. Variables can be referenced in templates, for instance to print text in a certain place. All data available in the context of a Flow are made available as variables for use in templates. When the source sends text called 'firstName', this code would print the contents:

${firstName}

In some cases, you might want to access variables that are nested in a structure called a 'hash'. For instance when you have an order confirmation and you need its id. This is how you get it:

${order.id}
 

Alternate/default values

Usually, the next question is: "What if the variable is missing?". Good question! Basically, we want you to make explicit decisions on what needs to happen when certain data is missing when you're sending a message. That's why all used variables are mandatory and will result in an error when missing. You can change this behavior by adding an exclamation mark: !. You can also, optionally, provide an alternate value:

Dear ${firstName!"customer"},

If the firstName variable is missing, the alternate value will be printed:

Dear customer,
 

If

If conditions can be used to make parts of your template conditional. Content and template logic (for instance another if) can be mixed within the conditional block. For instance, if you only want to display shipping information if relevant:

<#if shippingMethod == "regular">
  Your order will ship as soon as possible!
</#if>

If statements can also contain multiple conditions and have "elseif" and "else" clauses. Please refer to the Freemarker documentation for more examples.

 

List

If you have a list of items, for instance an order containing order lines, you can use the list directive to handle them one by one. This is often used in conjunction with HTML lists or tables, where each item represents a new row:

<table>
   <#list order.lines as line>
      <tr>
         <td>${line.description}</td>
         <td>${line.amount}</td>
      </tr>
   </#list>
</table>