Home | Dynamic Content | FreeMarker Functions: Split, Capitalize and Lowercase

FreeMarker Functions: Split, Capitalize and Lowercase

FreeMarker is a scripting language that ClickDimensions uses to render dynamic content in emails, but FreeMarker can also be used to manipulate the data that is pulled into emails. In this post, we will examine three particular FreeMarker expressions that can each be used on standard text within your email or on text that is dynamically inserted from a record in your CRM, providing a greater degree of control over how text displays in our emails: split, capitalize and lowercase.

Split Function

The FreeMarker split function allows you to divide a string of text along the occurrences of a secondary string or character and is used with the FreeMarker list function. The split function looks like this:

<#list “some,test,text”?split(“,”) as x>

– ${x}

</#list>

The function will examine the input string “some,test,text” and list out each substring that occurs between instances of the comma (the text can be split on any type of text, even full words or sentences, not just commas). The output for this example would be:

– some

– test

– text

Note that the split function will split the string at every instance of secondary string that it finds, so if, for example, the previous string looked like this:

Some,,test,text

The output would be:

– some

– test

– text

The blank list item is the result of the two adjacent commas.

A useful scenario where this could come into play in an email would be if you have a text area field on your lead record containing a comma separated list of different products that a customer has expressed interest in, and you want to display all of these products back to them in a list format rather than a block of options, like “product A, product B, product C, etc.” In the below example, I have a field on my lead called Products. The field contains the following items: TV, VCR, Microwave, Oven. The FreeMarker I want to use looks like this:

<#list “${Recipient.lead.new_products[0]}”?split(“,”) as product>

– ${product}

</#list>

${Recipient.lead.new_products[0]} is how the Products field is dynamically referenced.

When I add this into my email and send it to myself, I receive the following results in my inbox:

The first line shows how the data displays when I reference the Products field directly, and the rest of the text is how the Products field displays when using the split function.

Capitalize and Lowercase Functions

Capitalize and lowercase are similar functions that are both a bit more straightforward than split. The capitalize function capitalizes the first letter of each word in a given string. For example, the function below:

${“rhys saraceni”?capitalize}

This would convert “rhys saraceni” to “Rhys Saraceni.”

The lowercase function will lowercase any capitalized letters in the given string. For example:

${“RandOM CAps”?lower_case}

This would convert “RandOM CAps” to “random caps.”

While they are not particularly flashy, these functions can be used to ensure consistency in the formatting of dynamic content that you display to customers in your emails. This could be helpful to account for any typos made when inputting data or for cleaning up text that customers submit in a form.

A common scenario where you may want to use one of these functions would be:

${“${Recipient.contact.fullname[0]}”?capitalize}

This would dynamically insert a contact’s full name into your email and make sure that both their first and last name are capitalized.

FreeMarker expressions can be stacked, so both of these items could even be combined if you wanted to format text and also display it as a list. If we look at our previous Products field, let’s say that I had been a little inconsistent with the data I added to the field, and it now contains “TV, VCR, microwave, oven” instead of “TV, VCR, Microwave, Oven.” This time, I will use the following FreeMarker to pull the content into my email:

<#list “${Recipient.lead.new_products[0]}”?split(“,”) as product>

– ${“${product}”?capitalize}

</#list>

This will output the product list with all of the items in the list capitalized.

Happy Marketing!

About the Author:

mm
Rhys Saraceni is a Training Developer at ClickDimensions.

Leave A Comment