Templates

Syntax

The templates engine used in Communications is Thymeleaf, that is widely used framework for templating for html. We will apply it syntax and engine for email html templates and also other textual templates like sms or push notifications. The complete Thymeleaf Doc can be found Here for better understanding of the syntax, including utility objects description that may be very useful for some particular formatting of templates.

Additionally, we will include some basic usage examples that are the one more used in communication Templates.

Strings

Operation SMS
Format Example
Input Template Output
Insert variable string [(${stringVariable})] name=”Paco” Hi [(${name})] ¿How are you? Hi Paco, ¿How are you?
Check if empty ${#strings.isEmpty(stringVariable)} name=”juan” Is the name empty? [(${name.isEmpty})] Is the name empty? false
Compare with value ${#strings.equals(stringVariable,"value")} name=”pepe” Is the name pepe? [(${#strings.equals(name,"pepe")})] Is the name pepe? true
Show only n last characters [(${#strings.substring(contentCode,#strings.length(contentCode) - n,#strings.length(contentCode))})] msisdn=”612345678” We cancel the line ending with [(${#strings.substring(msisdn,#strings.length(msisdn) - 4,#strings.length(msisdn))})] We cancel the line ending with 5678

Numbers

Operation SMS
Format Example
Input Template Output
Insert number as it is provided [(${numberVariable})] amount=”327,1” I’ll give you [(${amount})] € I’ll give you 327,1 €
Insert number with n decimals [(${#numbers.formatDecimal(numberVariable,0,n)})] amount=”327,1” I’ll give you [(${#numbers.formatDecimal(amount,0,2)})] € I’ll give you 327,10 €

Conditional evaluation

Operation SMS
Format Example
Input Template Output
Switch depending on a String variable [# th:switch="${variableName}"][# th:case="Value1"]Text 1 to include[/][# th:case="Value2")}]Text 2 to include[/][# th:case="*"]Default text to include[/][/] item=”TV” I see [# th:switch="${item}"][# th:case="SIM"]a little SIM[/][# th:case="TV")}]a wonderful television[/][# th:case="*"]an unknown item[/][/] I see a wonderful television
Insert depending of boolean variable [# th:if=${booleanVariableOrExpression}]Text to include if true[/][# th:unless=${booleanVariableOrExpression}]Text to include if false[/] boolVar=<true/false> Is the variable true? [# th:if=${boolVar}]Yes, it is![/][# th:unless="${boolVar}"]No, it is not![/] If true → Is the variable true? Yes, it is!
Insert depending on week day [# th:switch="${#dates.dayOfWeek(dateVariable)}"][# th:case="1"]Text if Sunday[/][# th:case="2"]Text if Monday[/][# th:case="*"]Text any other day[/][/]Week days number: Sunday → 1, Monday → 2, …, Saturday → 7. dateVariable=23/04/21 (friday) What day is today? [# th:switch="${#dates.dayOfWeek(dateVariable)}"][# th:case="6"]It's friday!!![/][# th:case=\*"]Not friday yet... :([/][/] If sent on friday → What day is today? It’s friday!!!
Insert if not empty [# th:unless=${#strings.isEmpty(stringVariable)}] fixed text + [(${stringVariable})][/] stringVariable = 666112233 It is a SIM[# th:unless=${#strings.isEmpty(msisdn)}] linked to [(${msisdn})][/] It is a SIM linked to 666112233