format(data, formatString)

Tinderbox Icon

Operator Type:   Formatting
Operator Scope of Action:   Item

The operator format() converts various Tinderbox objects to strings. In quoted (") string arguments a \" is converted into a quotation mark (a.k.a. double quote), \n to a carriage return and \t to a tab.


The argument what is usually an attribute reference or expression.

The meaning of format_string depends on the type of object represented by what. Tinderbox data types Date, Set and Number are handled using different sets of arguments as described below.

If what is a date, the format string is the same as the format used by Tinderbox's date export codes.

For example:


gets the note's creation date and formats it as a "long local date" such as "Sunday, 23 March, 2007".

If what is a Set, the format string is the delimiter used to separate set elements:


For example


converts key attributes to a comma-separated list. Optionally, you may supply five arguments to format the set as an HTML list:


For example


will return HTML code for a bulleted list with each set member marked up as a list item. Note that the tags must be in double quotes.

To make this easier to use in a code export context, you might pass the output of format into another attribute and call the latter within the template with a ^get()^ code.

If what is a number, then the arguments are numeric and interpreted as follows:

format(what,precision[, width])

The precision argument controls the number of decimal places returned. The optional width argument allows the returned value to be a string left padded with spaces - e.g. to return a string with the same number of characters as submitted.

For example, if $MyNum is 3.1415927, then

format($MyNum,2,7) is " 3.14"

format($MyNum,2) is 3.14

format*$MyNum,0) is 3

If what is a color, format strings are ignored:


The operator returns the color in hex form, e.g. "#ff00ff".

Up: Full Operator List
Previous: firstWord(data)  Next: hue(color) 

[Last updated: 14 Dec 2009, using v5.0]

Google search aTbRef for:  

Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]

Creative Commons License

Made with Tinderbox