Formatting Your Data

There are many different ways to format your data. In this post, when we talk about formatting, we don’t mean styling (font, color, etc) – we are talking about altering the format of your data. For example, you have created a document that includes numbers, but the data comes through without pretty formatted numbers that include commas to separate the thousands. Or you may want to convert a word to all lowercase. Much of this formatting can be done pretty easily.

To format the merge field data, we're going to use what is called a "modifier".  This is a little piece of code that is added after the merge field name, separated with a pipe "|".

Here is a list of available modifiers:

Name Description Example
abbreviation Convert text to abbreviation (grab first letter of each word)

John Smith = JS

John Smith = J.S.

add_days Add days to date


age Convert date into age (years)


age_to_words Convert date into age in words

{$Birthdate|age_to_words} = 2 years 3 days 4 hours

bitly Convert URL to Bitly link


calendar Make calendar from array of dates


$dates = [{"name":"Make Offer", "date":"3/5/2017"}, {"name":"Submit Escrow  Check", "date":"3/21/2017"}, {"name":"Close Deal", "date":"4/15/2017"}]

capitalize Capitalize the first letter of a merge field


capitalize_sentences Capitalize the first word in each sentence


cat Append text to the end of a merge field

{$Name|cat:" is ready"}

csv_to_array Convert CSV string (or URL) to an array

{$csv = $file_url|csv_to_array}

currency_format Format a currency value

{$TotalAmount|currency_format:"$"} = $1,298.99

International Format:

date_format Change the format of a date

{strtotime("+ 5 days", strtotime($_date))|date_format:"m/d/Y"}
For more options, check out

decimal_to_words Convert a decimal/number to words

{$Ratio|decimal_to_words} = three and 7 tenths

default Set a default value for a merge field


expand_url Get real URL (follow redirects) from a shortened URL


get_file Download file from URL

{$text = $url|get_file}

html_safe Convert characters to HTML safe characters


html2office Convert HTML to Office doc formatting


html2text Convert HTML to plain text


implode Combine list of array values into single string with a separator

{implode(", ", $Colors)}
comma separated list of the $Colors

int_number Convert international number to US format (for calculations) 

 {$Total = $Subtotal|int_number + $Tax|int_number}

list List array values in a commas separated list

{$Colors|list:",":"and"} = Red, Green, and Blue

lower Convert all characters to lowercase

Formstack Documents = formstack documents

markdown2html Convert markdown to html


money_to_words Convert price to words

10.50 = ten dollars and 50 cents

11 = eleven euros

nl2 Convert new-line characters to given string

{$Description|nl2:", "}

nl2br Convert new-line characters to HTML line breaks <br>


nl2p Convert new-line characters to HTML paragraph


number Convert merge field to a number (for calculations)

10,231 = 10231

number_eu_to_us Converts a number from EU format to US


number_us_to_eu Converts a number from US format to EU


number_format Change the format of a number (commas and decimals)

5234.35 = 5,234.35

International format (comma for decimal place)

number_to_words Convert number to words


pad Pad merge field with the given string, so it is the given length

123456 = 00000012345

parse_url Searches string for a URL


phone_format Format a phone number

{$WorkPhone|phone_format:"(%3) %3-%4"}
123-555-7890 = (123) 555-7890

{$phone|phone_format:"%3.%3.%4"} = 123.456.7890

replace Search and replace a string in a merge field

123 S Main Street = 123 S Main St

round Round a number to number of decimal places provided


spacify Insert a space (or string) in between each character in merge field

Thomas = T h o m a s

123456 = 1-2-3-4-5-6

state_abbreviation Convert US State name to abbreviation


strip Replace all new lines, spaces, and tabs with a single space


strip_tags Remove all HTML tags from merge field

{$Description|strip_tags:"<br>"} (allow <br>)

substr Create a sub-string of the merge field


text2html Convert text to HTML


time_to_words Creates a text representation of the number of seconds


translate Translate text into another language


via Google Translate - Languages

truncate Truncate/shorten the merge field to the given length

{$Description|truncate:140}    (140 characters)

ucfirst Capitalize the first letter in the first word


ucwords Capitalize the first letter in each word


upper Convert all characters to uppercase

Formstack Documents = FORMSTACK DOCUMENTS

xml_safe Encode merge field data for XML (Office) docs

{strftime("%d %B %Y", strtotime($_date))|ucwords|xml_safe}


  • International Date/Translation
    • You can print a date like this: {strftime("%d %B %Y", strtotime($_date))|ucwords}
    • More formatting options for strftime:


For more information on using variable modifiers, please visit

Was this article helpful?
13 out of 16 found this helpful


  • The numbers are formattet wrong. It does not take into account that in Norway we format differently. one million is 1 000 000,- or 1.000.000,- The decimal punktation is a comma , and thousand seperator is SPACE or DOT

  • Hi Einar,

    We have added an international number example above that uses a comma for the decimal and a dot for the thousands separator.  You can actually customize all of the punctuation using {$VariableName|number_format:2:'DECIMAL POINT':'THOUSAND SEPARATOR'}


  • For replace function,I just check in smarty it has replace ,so is supported by Webmerge

  • Yes, you can use the replace function

  • How we do REPLACE(REPLACE(A, W, X), Y, Z)) using Web Merge?

  • It will actually be easier to use the php str_replace function like this:

    {str_replace(str_replace(A, W, X), Y, Z))}

    If you have more questions, please create a support ticket and we can help you directly!

  • Is it mean that I can direct use PHP syntax in Word document although I will be generated document from Salesforce?

  • That's correct - we allow basic PHP functionality (like string functions) inside your templates.

  • I have a danish social security numbers for input.

    By default webmerge makes it look like this: 1,234,561,234
    I need the following format: 123456-1234

    How do i go around that?

  • Hi Kasper,

    You can use the "phone_format" modifier (even though it isn't a phone number), like this: {$ssn|phone_format:"%6-%4"}

  • In webmerge there is no field that records the year of creation for the field map.

    I have only full dates.

    Is it possible to use a merge only part of the date, so i only pull the year?

  • Hi Kasper,

    Yes, you can use the "date_format" modifier like this: {$StartDate|date_format:"Y"} and that will only print the year.

  • How do I format the results of a calculation?

    For example:

    If {$Variable1*($Variable2/Variable3)-(Variable1*Variable4)} results in 1000000, how do I format the result to to look like 1,000,000?

  • Hi Todd,

    Like this: {($Variable1*($Variable2/Variable3)-(Variable1*Variable4))|number_format}

  • Can you show all the options for a phone format modifier?

  • Hi Albert,

    We've updated the article above to show an example, but here it is:

    {$WorkPhone|phone_format:"(%3) %3-%4"}

    The %[Number] indicates how many digits from the number to show.

  • Turns out you can do a lot more than just format numbers. You can use conditionals to create arrays which can be used in the data routing rules to create batch copies of documents with an incoming stream of data. I'll write something up for you Jeremy if you want and you can post as a tip here.


  • Thanks Alex!

  • Date field {$INTAKE_DATE} coming out of Salesforce looks like this:

    2017-07-03 00:00:00

    Attempting to format it like this:


    Based on the PHP article, it looks like I should do this:


    Error upon file upload:

    Error merging document: Syntax Error in template "string:" "{$INTAKE_DATE |date_format:"n/j/y"}" - Unexpected "|"

    It apparently doesn't like the pipe character ...?

  • My experience is that you have to specify the format using the correct syntax for date, month, and year. Previously, I've had success with {$INTAKE_DATE|date_format:"d/m/Y"} or similar. The PHP thread they've put up designates the numeric representation of the day as a capital 'N' etc.

    They've got a list of variable modifiers at the top of the thread, as well.

  • Hi Matthew,

    It looks like there's a space after your merge field and before the pipe. Please remove that space and you should be good to go :)

  • @Jeremy, you were right. Can't believe I missed that! Works now. :-)

  • Hi,
    I am using Smarty {$fields} to populate a word presentation. Is it possible to format a field into £ sterling using a modifier? so if someone enters '300' in a freetype box it will appear as £300.00? Or should this be done using Word fieldmerge?

  • Hi Daniel,

    You just need to place the £ outside your merge field like this:


    That should do that trick!

  • Thank you for this, Jeremy!

  • What would I use to make time display without the leading zero for 1-9?

  • You would want to use something like this: {$start_time|date_format:"g:ia"}

    More formatting options:

  • This is amazing! Never used this feature before. Thanks for explaining this! Webmerge is awesome.

  • Looking for how to change the time format for 12h vs. 24h, which appears to be the default. Any hints?

  • Hi Cory,

    You would want to use something like this: {$start_time|date_format:"H:i"}

    More formatting options:


Please sign in to leave a comment.