Tinderbox v9 Icon


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

 Function  [other Function type actions]

 Item  [operators of similar scope]

 Formatting  [other Formatting operators]


 As at baseline


If data is a List or Set, returns the list into a String, with discrete list elements formatted as per the formatStr:

$MyString = $MyList.format("formatString"); 

The process preserves original data; duplicate values in lists are maintained. For example

$MyString = $DisplayedAttributes.format(", "); 

converts Displayed Attributes to a comma+space-separated list. To put each item on a separate line use this:

$MyString = $DisplayedAttributes.format("\n"); 

Doing the same for HTML export, you might want the rendered text to have each value on a new line so use:

$MyString = $DisplayedAttributes.format("<br>"); 

Thus $Text may be created from concatenation of other texts:

$Text = (collect(children, $Text)).format("\n"); 

Optionally, you may supply four arguments to format the list or set as an HTML list:

$MyString = List/Set.format("listPrefix","itemPrefix","itemSuffix","listSuffix"); 

For example:

$MyString = $Classes.format("<ul>","<li>","</li>","</ul>"); 

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 have each element on a separate line and indent the items add tabs and line breaks:

$MyString = $Classes.format("<ul>\n","\t<li>","</li>\n","</ul>\n"); 

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 ^value()^ code. By a repeated use of format it is possible to export lists of links.

Trailing semi-colons

Although Tinderbox happily accepts user-input lists with a trailing semi-colon after the last item, i.e. "cow;ant;" vs. "cow;ant"", trailing semi-colons can be problematic when formatting lists. This is because that process emits an extra empty item and preceded by the user specified delimiter. Thus the output my have an unwanted trailing delimiter. If encountered, the best approach to dealing with this is to clear the source data.

Similar functions

This supplements the existing format() function.