Creates an arbitrary number of instances of a tag according to a definition.
Each instance within the array can then be referenced and manipulated independently using a unique index number.
<index:array size=10 *= <box {This is box</n>number <index>.}> >
— Creates and presents 10 boxes on the screen, each containing predefined text with that box's number from 1 to 10.
The array tag's primary field specifies the index number of the current element within the array.
An array creates a specified number of presentation tags or persistent logic tags. All tags are created according to a common definition, but after creation each tag in the array can be accessed and manipulated using its numerical position (known as its array index) within the array.
Each tag within the array may be referred to as an array 'element'. The definition used to create array elements must be specified in the * field before the array tag is complete. Once it has been defined, this template definition cannot be altered during the lifetime of the array tag instance. An array element definition must consist of exactly one tag, defined with any fields desired. The primary and secondary fields of that tag may themselves contain other tags as required.
The size field specifies the total number of elements in the array. Array elements are allocated index numbers from 1 up to and including the value of the size field. After the array tag is complete, the value in the size field can be changed at any time thereafter in order to resize the array. If the size value is reduced, excess elements at the end of the array are deleted. If the size value is increased, new elements are created at the end of the array according to the initial definition.
The array tag's primary field is used for getting or setting the current array index in order to access an individual element in the array, which can then be accessed using the * field.
A reference to the current element can be obtained using *.&
. This is useful in cases where continued access to a particular element is needed even after the array's current index has been changed.
In order to provide access to the primary field of an array tag, an array tag should always be given a name. Take care to ensure the name chosen does not conflict with an existing tag or field of the same name within the same scope.
This example takes a list of colors provided in a vector, and then creates an array of checkBoxes on the screen containing the colors from the vector.
Afterwards, a new color is inserted into the list at position 3. First the array's primary field is set to 3, then the .insert operation is used to create a new element in that position. The array definition causes the new element to be created with the color {blue}
, so the new checkBox's primary field is then changed to {Magenta}
, as is the color field of the new array element.
<optionList:vector {Red},{Green},{Blue},{Yellow},{Cyan}> <optIndex:array size=optionList.# *=<span color=<optionList.@ optIndex> {<opt:checkBox | optionList.@ optIndex></n>}> > <optIndex=3><optIndex.insert> <optIndex.*.opt={Magenta}> <optIndex.*.color={Magenta}>Red