format

Formats the content within the tag based on the tag parameters

Example

[%format type:'currency'%][@price@][%/format%]

Usage

Format tags are used manipulate the output of data created by Maropost Commerce Cloud Template Tags. Here are some examples:

csv - Preparing text to be exported in a CSV file

Escapes the " character in a string so it can be used in a CSV export. Replaces " with "":

[%format type:'csv'%]Shinkansen is called a "bullet train"[%/format%]

Displays Shinkansen is called a ""bullet train"".

currency - Adds decimal places to a number

Add decimal point and two decimal places to a number:

[%format type:'currency'%]19[%/format%]

Displays 19.00.

date - Printing the current time/date

The format tag allows you to print the current date / time by simply adding the word now within the tag:

[%format type:'date' format:'#D #K #Y at #H:#I:#S'%]now[%/format%]

Displays 15 August 2018 at 13:06:08.

number - Add thousands separator and decimal places

[%format type:'number' sp:',' dp:'2'%]1900[%/format%]

Displays 1,900.00.

percent - Adds a percentage sign to the end of the number

Rounds the number and displays a percentage sign:

[%format type:'percent'%]95.7[%/format%]

Displays 96%.

text - Change to lower case and truncate

Changes to lower case and displays the first 16 characters:

[%format type:'text' case:'lower' maxlength:'16'%]One so immersive the device[%/format%]

Displays one so immersive.

Parameters

Name Options Description
`type:''` `csv`, `currency`, `date`, `number`, `percent`, `text`

The type of format you wish to apply, each type has its own set of parameters that are specific to the type

Options
`csv` Prepares strings to be used in a CSV file
`currency` Format currency
`date` Format date and/or time
`number` Format numbers
`percent` Format as a whole percentage
`text` Format text / strings
`dpno_zero:''` `0`/`1` Works with type currency, a boolean that when true will remove the decimal place if the cents value is `0` or `00`
`add:''` String Works with type date. Determine time value you would like to add to remove from current timeframe, example: `-1 hour`, `1 day`, `5 min`, `2 month`
`format:''` Code (see chart)

Works with type date and determines the output of the date format

Year
`#Y` Numeric representation (4 digits)
`#y` Short numeric representation (2 digits)
Month
`#M` Numeric representation (04)
`#m` Numeric representation without leading zero (4)
`#K` Textual representation (April)
`#k` Short textual representation (Apr)
Date
`#D` Numeric representation (07)
`#d` Numeric representation without leading zeros (7)
Day
`#W` Textual representation (Friday)
`#w` Short textual representation (Fri)
Hours
`#H` 24-hour numeric representation (04:30)
`#h` 24-hour numeric representation without leading zeros (4:30)
`#G` 12-hour numeric representation (09:45)
`#g` 12-hour numeric representation without leading zeros (9:45)
Minutes
`#I` Numeric representation (06)
`#i` Numeric representation without leading zero (6)
Seconds
`#S` Numeric representation (09)
`#s` Numeric representation without leading zero (9)
AM/PM
`#A` Uppercase ante meridiem and post meridiem (AM or PM)
`#u` Lowercase ante meridiem and post meridiem (am or pm)
Unix
`#U` Unix epoch time (seconds since 1970-01-01 00:00:00 GMT) given a local time
`#u` Unix epoch time (seconds since 1970-01-01 00:00:00 GMT) given a GMT time
Timezones
`#Z` Numeric representation of the timezone offset (+1000)
`dp:''` Integer Works with type number, it will format the number to the specified number of decimal places
`pf:''` String Works with type number and currency, this string will be prepended to the output. Eg. "$" or "AUD $"
`sp:''` String Works with type number, adds the string specified at every thousand interval. Typically you would place a `,` here, so `10000` would be formatted as `10,000`
`tl:''` String Works with type number, adds the string specified to the end of the number formatted
`tl_plural:''` String Works with type number, generates a text block based on the value, so if the item is plural ie. There is two, we might print the text "items have"
`tl_unit:''` String Works with type number, generates a text block based on the value, so if the item is singular ie. There is one, we might print the text "item has"
`addbr:''` `1`/`0` Works with type text. Converts newline characters to `
` tags
`case:''` `upper`, `lower` Works with type text, forces the content to either be upper or lower case
`maxlength:''` Integer Works with type text, limits the maximum amount of characters contained within the tag
`noeol:''` `1`/`0` Works with type text. Removes carriage returns from the text
`nohtml:''` `1`/`0` Works with type text, when true it will escape HTML
`rmhtml:''` `1`/`0` Works with type text, when true it will strip HTML
`trim:''` `e`, `l`, `r`, `a` Works with type text, trims out spaces depending on the value used. `l` & `r` trim out spaces to the left and right respectively, `a` trims out all space between text and `e` trims out all space between text down to the integer attached to it, so for example, trim:'`e1`' will trim down to 1 space, removing the potential for double spaces
`truemaxlength:''` Integer Works with type text, limits the maximum amount of characters contained within the tag after `nohtml`/`rmhtml` has been applied
`wordlength:''` Integer Works with type text, limits the maximum number of characters before the word is hyphenated and the remainder of the word appears on a new line

Was this article useful?

Be notified when this page is updated. Optional.