Skip to main content
Version: Next

Loops

Certain data fields in a collection contain multiple elements (such as Participants, Comments, Events). You can loop through any of these elements and selectively output data.

The syntax for a loop is structured as follows. You can name the variable X whatever you like:

+++FOR X IN data_field_that_is_loopable+++    // Starts the loop.

+++= $X.key+++ // Output the data you desire.

+++END-FOR X+++ // Ends the loop.

When using a FOR-loop, do not forget to include the $ sign on the reference item.

Utilizing helper functions and conditionals can also help output specific information that you define (e.g., specific custom fields, event types, or event fields).

Example Loops on Collections

Here are several examples of how loops can be used on an Advanced Doc Export of a Collection.

Participants on a Collection

Assume we are attempting to loop through the participants in a collection and desire to output each participant's full name and email in a bulleted list. This would look like the following:

+++FOR person IN participants +++

- +++= $person.fullName +++
- +++= $person.email +++

+++END-FOR person +++

All Custom Fields on a Collection

This exports all custom fields on a collection with the field name and value. The _HTML helper is used to account for formatting for rich text fields.

+++ FOR field in customFields +++            

+++= $field.name +++

+++HTML _html($field.value) +++

+++ END-FOR field +++

Loop within a Loop

Sometimes, a loop may have items that have accessible loops themselves. A great example of this is going through all attached events on a collection and output each event's name, then each event detail field's name and value as an indented list:

+++ FOR event in items +++                       // Starts the items loop.

+++= $event.eventTypeTitle +++

+++ FOR field in $event.eventDetails +++ // Starts a second loop in the event details.

- +++= $field.name +++: +++= $field.value +++ // Outputs the bolded field name and value as a bullet point.

+++ END-FOR field +++ // Closes the second event details loop.

+++END-FOR event +++ // Closes the items loop.

Example Loops on Events

Here is an example of how a loop can be used on an Advanced Doc Export of an Event.

Exporting All Event Data Fields

The following code can be copy-pasted as is to export the name and value of the event's data fields:

+++FOR field IN eventDetails+++    // Starts the loop on eventDetails

+++= $field.name +++ // Output the name of the field
+++= $field.value +++ // Output the values of the field

+++END-FOR field+++ // Ends the eventDetails loop.