Referencerepeat

<repeat>

Repeats template content for each item in a source

<repeat> is a General Operator component that performs the requested operations in an iterative manner over the component specified (typically, this is a list or an array). If the specified component is a <sequence>, a shorter method is to use the <repeatForSequence> component.

The behavior of the <repeat> component is similar to a for loop in other programming languages.

Attributes and Properties

Attributes for <repeat>

Other (5)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

for

group. The collection of items to iterate over when generating repeats.

indexName

text. Name to bind the current 1-based index to inside the repeat template.

type

text. Component type used to wrap each item in the source.

valueName

text. Name to bind the current item to inside the repeat template.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

Whether the generated repeats should be treated as responses for assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <repeat name="r">

Common to all components (3)
$r.doenetML

text. The DoenetML source code that produced this component.

$r.hide

boolean. Whether to hide this component from the rendered output.

$r.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: <repeat> a series of rectangles within a <graph>

A <repeat> can be used to generate multiple graphical elements at once when placed within a <graph>.


Example: <repeat> a user-specified number of inputs

A <repeat> can be used to generate a user-specified number of <mathInput> components. For an alternative way to do this, see the <repeatForSequence> component.


Example: <repeat> a list of <text> elements

A <repeat> can be used with non-mathematical components as well. Individual entries can be accessed using array notation.

Example: Use <repeat> in a combinatoric way

Use nested <repeat> components to iterate across all combinations of the specified components.


Example: Use <repeat> in a selective way

To achieve parallel iterative behavior, a combination of the indexName and valueName attributes can be used.


Example: Generate a user-specified number of random <point> components

A <repeat> can be used to generate a user-specified number of randomly placed <point> components. For an alternative way to do this, see the <repeatForSequence> component.