FORMAT functions

With format functions, you can expand the Field formatting functionality in Text Blocks and Quick Templates in KCM Designer.

Currently, custom format functions cannot be applied to Editable Text Blocks in KCM ComposerUI, except for KCM ComposerUI if it is integrated using the tbeformatfunctions parameter.

Format functions are specified using the FORMAT keyword prefix. Format functions can only be defined in Code Libraries, and they cannot be defined in conditional statements or other nested constructs.

FORMAT FUNC TEXT function (CONST TEXT input)
DO
  ...
OD

FORMAT FUNC TEXT function (CONST TEXT input; CONST TEXT par1; ...)
DO
  ...
OD

A format function must have at least one CONST TEXT parameter that receives the data to be formatted. The function must return the formatted data as TEXT.

Format functions can have additional CONST TEXT parameters that can be used to pass additional information. These parameters are optional. If a Text Block or a Quick Templates omits parameters, they are passed as empty texts. Excess parameters in a call are ignored.

The escape character for parameters of the custom format functions is the backslash character (that is, \).

Format functions have access to the Data Backbone through the _data variable and can use any Template scripting language functionality.

To use Microsoft Word instructions in Code Libraries, you must assign content containing Microsoft Word instructions to Data Backbone Fields in a Master Template. Use these Fields in Code Libraries when manipulating layout. Microsoft Word instructions typed directly in Code Libraries are stripped. Microsoft Word instructions are also stripped for the AiaDocXML output and HTML output.

FORMAT
FUNC TEXT dotteddate (CONST TEXT date)
DO
  ASSIGN dotteddate := fragment_of_characters (date; 7; 2) + "."
                     + fragment_of_characters (date; 5; 2) + "."
                     + fragment_of_characters (date; 1; 4)
OD

Here is an example of the Function used in a Text Block or a Quick Template to print a date in DD.MM.YYYY format.

... «[Policy.Date:dotteddate]» ...

FORMAT
FUNC TEXT logo (CONST TEXT blob)
DO
  ASSIGN logo := insert_image ("Corporate Logo"; x:="15cm"; y:="1.25cm"; width:="4cm"; height:="2cm"; base64data:=blob)
OD

Here is an example of the Function used in a Text Block to insert a base64 encoded image from a Field in the Data Backbone in the upper right corner of the page.

... «[Corporate.Logo:logo]» ...

FORMAT
FUNC TEXT verb (CONST TEXT gender; CONST TEXT male; CONST TEXT female; CONST TEXT other)
DO
  IF   gender = "M" THEN ASSIGN verb := male
  ELIF gender = "F" THEN ASSIGN verb := female
  ELSE                   ASSIGN verb := other
  FI
OD

The Function used in a Text Block or a Quick Template implements conditional text in a Text Block.

... If the «[Customer.Gender:verb|customer|customer|customers]»
 «[Customer.Gender:verb|prefers|prefers|prefer]»,
 «[Customer.Gender:verb|he|she|they]» can pay in ...

You cannot use word processing layout and instructions in Quick Templates. Word processor instructions produced with the FORMAT functions, including the use of insert_image and insert_signature, are removed from the result document.