Kauri Documentation
 PreviousHomeNext 
11.4.2 i18n() functionBook Index11.5 Server API

11.4.3 format() function

The format function takes a variable number of arguments:

11.4.3.1 Format string syntax

11.4.3.1.1 Basics

The format string contains placeholders using  {...} syntax. If you want to insert {...} literally, escape it using backslash: \{...}.

The placeholder contains the index of the parameter to insert, and optionally some formatting arguments.

A simple format string thus might look like:

The quick {0} fox jumps over the {1} dog.

Used with the format function in the template language:

${format('The quick {0} fox jumps over the {1} dog.', 'brown', 'lazy')}

If the first argument would be part of a resource bundle below the key 'quick_dog_phrase', the usage would be:

${format(i18n('quick_dog_phrase'), 'brown', 'lazy')}
11.4.3.1.2 Formatting arguments

Formatting arguments are useful when the value to insert is not a string, but a date or number.

The full format of the placeholders is:

{index,type,style_or_pattern}

The parts are:

Dates will be adjusted to the user's timezone when formatting.

The table below lists the available types and styles.

Object type

Type

Style / pattern

dates

(java.util.Date
or
org.joda.time.ReadableInstant)

date

none / S / M / L / F (short/medium/long/full)

time

none / S / M / L / F

datetime

none / two characters from S / M / L / F / -

dtpattern

A joda-time date/time formatting pattern.

numbers

(java.lang.Number)

int

none

nrpattern

A Java SimpleNumberFormat pattern.

11.4.3.1.3 Examples
Format a single date:
${format("{0,date}", someDateObject)}

Format a single date using a pattern:
${format("{0,dtpattern,dd/MM/yyyy}", someDateObject)}

Format a date-time using long date format and small time format:
${format("{0,datetime,LS}", someDateObject)}
 PreviousHomeNext 
11.4.2 i18n() function11.5 Server API