This version is out of date, covering development from v4.6.0 to v4.7.1. It is maintained here only for inbound reference links from elsewhere.
Jump to the current version of aTbRef.
|A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Scope : Item-based operators : format(data, formatString)||aTbRef Site Map|
|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.
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:
converts key attributes to a comma-separated list. Optionally, you may supply five arguments to format the set as an HTML list:
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:
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: Item-based operators|
|Previous: firstWord(data)||Next: hue(color)|
Licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
[See aTbRef CC licence Attribution/Waiver info info]