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.

Here are some examples...

  • Format a number:
    • {$VariableName|number_format:2}
    • Example: 5235.34 = 5,235.34
    • The pipe "|" indicates a formatting function. The 2 indicates the number of decimals
    • International: {$VariableName|number_format:2:',':'.'}   = 5.235,34  (this uses a comma for decimal place and dot for thousands separator)

  • Convert word to lowercase
    • {$VariableName|lower}
    • Example: WebMerge = webmerge

  • Convert new line characters to HTML break lines
    • {$VariableName|nl2br}
    • This modifier converts new line characters “ ” to HTML <br />

  • Format a date
    • {$StartDate|date_format:"m/d/Y"}
    • {strtotime("+ 5 days", strtotime($_date))|date_format:"m/d/Y"}
    • For more options, check out www.php.net/date

  • Format a phone number
    • {$WorkPhone|phone_format:"(%3) %3-%4"}
    • The %[Num] in the format value indicate how many digits to show

  • International Date/Translation
    • {$_ = setlocale(LC_TIME, "spanish")}
    • Then you can print a date like this: {strftime("%d %B %Y", strtotime($_date))|ucwords}
    • More formatting options for strftime: http://php.net/strftime

 

For more information on using variable modifiers, please visit http://www.smarty.net/docs/en/language.modifiers.tpl

Have more questions? Submit a request

18 Comments

  • Avatar
    Einar v/Nøkkelhus AS

    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

  • Avatar
    Jeremy Clarke

    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'}

    Thanks!

  • Avatar
    Nur Husnidha Hussain

    For replace function,I just check in smarty it has replace http://www.smarty.net/docs/en/language.modifier.replace.tpl ,so is supported by Webmerge

  • Avatar
    Jeremy Clarke

    Yes, you can use the replace function

  • Avatar
    Nur Husnidha Hussain

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

  • Avatar
    Jeremy Clarke

    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!

  • Avatar
    Nur Husnidha Hussain

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

  • Avatar
    Jeremy Clarke

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

  • Avatar
    Kasper Dam

    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?

  • Avatar
    Jeremy Clarke

    Hi Kasper,

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

  • Avatar
    Kasper Dam

    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?

  • Avatar
    Jeremy Clarke

    Hi Kasper,

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

  • Avatar
    Todd Heine

    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?

  • Avatar
    Jeremy Clarke

    Hi Todd,

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

  • Avatar
    Albert Trevino

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

  • Avatar
    Jeremy Clarke

    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.

  • Avatar
    Alex Sirota

    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.

     

    Edited by Alex Sirota
  • Avatar
    Jeremy Clarke

    Thanks Alex!

Please sign in to leave a comment.
Powered by Zendesk