listFormat: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(added more examples)
Line 18: Line 18:
</source>
</source>
(prints items on separate lines)
(prints items on separate lines)
<source lang="mtmacro" line>
[R: listFormat( getSelectedNames(),
    "<select name='test'>%list</select>",
    "<option value='%item'>%item</option>",
    "" )
]
</source>
(creates an option list input (drop-down list selection) for an html form, with the names of selected tokens)
Convert a string list to html list:<source lang="mtmacro" line>
[R: listFormat( "apple, bear, cat", "<ul>%list</ul>", "<li>%item</li>", "" ) ]
</source>
Produces:<ul>
<li>apple</li>
<li>bear</li>
<li>cat</li>
</ul>
}}
}}
[[Category:String List Function]]
[[Category:String List Function]]

Revision as of 17:53, 23 March 2010

listFormat() Function

Returns a custom-formatted version of the list.

Usage

[ listFormat(list, listFormat, itemFormat, separator) ]
[ listFormat(list, listFormat, itemFormat, separator, delim) ]
  • listFormat is a string that is emitted once. It should contain the text "%list", which is replaced with the formatted items.
  • itemFormat is emitted once per item. Each instance of "%item" in the string is replaced with the value of the list item.
  • separator is emitted in between the formatted items.

Example

[ listFormat("apple,bear,cat", "BEGIN LIST<br>%list<br>END LIST", "This item is: %item", "<br>") ]

(prints items on separate lines)

[R: listFormat( getSelectedNames(), 
    "<select name='test'>%list</select>", 
    "<option value='%item'>%item</option>", 
    "" ) 
]

(creates an option list input (drop-down list selection) for an html form, with the names of selected tokens)

Convert a string list to html list:
[R: listFormat( "apple, bear, cat", "<ul>%list</ul>", "<li>%item</li>", "" ) ]
Produces:
  • apple
  • bear
  • cat