OpenWGA 7.0 - TMLScript reference

Method :

buildOptions(contents, [titleExpression, [emptyTitle]])

On object WGA
Usage Builds options for WebTML form inputs from a list of contents

Use this method to build the options of WebTML form inputs whose choices are based on content documents. This will be the case if you want to store them as content relations, but may also be the case if you want to store document keys for a choice of documents.

The method takes a list of content documents and builds a list of option strings from them. The titles of these options are either the titles of the content documents or the result of a title expression given as parameter. The option values will always be the struct keys of the documents in the list (which is mostly used to store relations to documents of equal languages).

If you use WGA.buildOptions() inside a dynamically calculated attribute options of your WebTML input tag then you can return the result list directly. The list entries will automatically be concatenated using commas to form the attribute content which is directly the right format to define options in this attribute.

Normally the returned options list will only host entries for the content documents in the list. If you add the "emptyTitle" parameter it will also host an entry for an empty value at the top of the list.


contents (List):

List of WGAPI content objects like returned by this.content() that should be used to calculate the options

titleExpression (String, optional):

A TMLScript expression that is evaluated against the individual contents to form the title of the options. Omit it to simply use the content titles as option titles.

emptyTitle (String, optional):

A title that is used for an entry that represents an empty value. Omit it to have no empty value entry.

Return value List of Strings, representing input options
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events

The following example builds a list of three content documents with unique names for demonstration purposes and the uses it to build an options list via WGA.buildOptions():


cons = WGA.createList();





<tml:input name="startpage" type="select" relationtype="normal" options="{WGA.buildOptions(cons)}"/>

The following is a more complex example: We retrieve the options to present from HDBModel using HDBModel.getRelationTargets(). But we do not want the document titles to be displayed as options. Instead we display the item 'company_name' by adressing it in the titleExpression parameter. Then we also want to customize an "emptyTitle" to be "--- Please select ---".

Because this is a rather complex expression we calculate it in a separate script block and hand over the result as variable "companyOptions" to the input tag:


companyOptions = WGA.buildOptions(HDBModel.getRelationTargets(content(), 'project', 'company'), 'company_name', '--- Please select ---')


<tml:input name="company" type="select" relationtype="normal" optionsitem="companyOptions"/>