List/Set.format("formatString")

Tinderbox Icon


Operator Type:   Function
Operator Scope of Action:   Item
Operator Purpose:   Formatting

List/Set.format("formatString")

New to v5.8.0, if data is a List or Set, the formatString is used to separate set elements:

$MyList.format("formatString") 

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

$KeyAttributes.format(", ") 

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

$KeyAttributes.format("\n") 

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:

List/Set.format("listPrefix","itemPrefix","itemSuffix","listSuffix") 

For example:

$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:

$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.

This supplements the existing format() function.


Possible relevant notes (via "Similar Notes" feature):

Up: Item-based operators

A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Scope : Item-based operators : List/Set.format("formatString")

Quicklinks: Attributes | Action Codes | Export Codes | Designators | Date Formats | aTbRef Site Map

[Last updated: 16 May 2012, using v5.11.1]


Search:

Google search aTbRef for:  


Creative Commons Licence

aTbRef by Mark Anderson is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

[See aTbRef CC licence Attribution & Waiver info]

Made with Tinderbox