format

Formats the content within the tag based on the tag parameters

Example

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

Usage

Format tags are used to 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 - display provided value as a price

Adds currency symbol, decimal point, and two decimal places to a number:

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

Displays $19.00.

date - Generate a datetime or format an existing one

The date value can either be an exact or partial datetime, e.g: [@arrival_date@], [@date_placed@], 2023-01-01 14:00:00, 01/01/2023. Or it can be a relative string, e.g: 10 days time, 1 year ago, now. Available relative terms: {number} [year|yr|month|mon|week|wk|day|hour|hr|minute|min][s] [ago|time] [eom|som] [now|today] where:

  • 'ago': Specifies a datetime in the past
  • 'time': Specifies a datetime in the future
  • 'eom': End Of Month
  • 'som': Start Of Month
  • 'now': Current datetime, down to the second
  • 'today': Current datetime, down to the day
[%format type:'date' format:'#D #K #Y at #H:#I:#S'%]now[%/format%]

Displays 15 August 2023 at 13:06:08.

number - manipulate provided value to add or remove decimal places, round the value, or append/prepend text

Add a comma separator for larger numbers and include decimal places:

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

Displays 1,900.00.

percent - convert provided value into a percentage

Rounds the number and adds a percentage sign:

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

Displays 96%.

text - manipulate provided text value to change case, length, trim or remove, etc

Change to lower case and display 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, set a time value you would like to add or remove from a provided datetime, example: `-1 hour`, `1 day`, `5 min`, `2 month`
`unix_timestamp:''` epoch number Works with type date, use instead of providing a date value. Formats a provided unix timestamp, e.g: `1700809303` to `24/11/2023`
`default:''` String Works with type date, fallback if the date value specified isn't a valid datetime - can be plain text or a B@SE tag
`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)
`#N` Numeric day of week from 1 (Monday) to 7 (Sunday) (6)
`#n` Numeric day of week from 0 (Sunday) to 6 (Saturday) (6)
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)
`#a` 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"
`round:''` `up`/`down` Works with type number, rounds the value up or down to the nearest whole number
`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.