Skip to content

Generating Questions from Lists

Surveys & forms

Lists let you write one question row and have Testable expand it into a question per item, or feed a whole set of items into a single question’s response options. This keeps your question content separate from the survey structure, so the same list can drive questions, options, and matrix rows.

A list is a named set of items. You can define one by uploading a CSV file in the Files tab, or by initialising it inline in the script column.

Inline definition:

%animals% = ['dog', 'cat', 'bird', 'fish']

You can also build lists dynamically during the experiment, for example by collecting participants’ responses with addToList(). Both inline definition and dynamic building are covered in Scripts.

Use %listname% in the head or body column to display all items from the list:

head = Please rate each of the following: %animals%

Use #listname# in the head column to automatically generate a separate question row for each item in the list:

head = How much do you like #animals#?

Testable expands this into one question per item at runtime.

Controlling page breaks for generated questions

Section titled “Controlling page breaks for generated questions”

By default, consecutive form rows collapse onto a single page. When #listname# generates multiple questions, you control how they are paginated with the pageBreak column:

ValueBehaviour
afterAllAll generated questions appear together on one page; the break falls after the last generated question
after (or 1)Each generated question appears on its own page
beforeA page break is inserted before each generated question

Use %listname% in responseOptions to turn list items into selectable choices:

responseType = radio
responseOptions = %animals%

Use %listname% in responseRows to create a matrix question where each list item becomes a row:

headresponseTyperesponseOptionsresponseRows
How important are the following?radionot important; neutral; important%attributes%

Append .random or .sample(x) to randomise or sub-sample list items:

responseOptions = %animals.random%
responseOptions = %animals.sample(2)%
  • .random presents all items in random order
  • .sample(x) randomly selects x items from the list

The same suffixes work on #list# wildcards (#animals.random#, #animals.sample(2)#), independently of the listOptions column.

Combining multiple lists: parallel and nested

Section titled “Combining multiple lists: parallel and nested”

By default, multiple #list# wildcards in the same row loop in parallel: one item from each list per generated question, advancing together. Use the listOptions column to switch to nested looping, where every combination is generated:

headlistOptions
What do you think about #animals# and #traits#?nested
What do you think about #animals# and #traits#?nested(animals, traits)
What do you think about #animals# and #traits#?parallel
  • nested generates every combination of items across all the row’s lists
  • nested(list1, list2) is the same, but only over the named lists; unlisted lists run in parallel
  • parallel is the default; lists advance together one item at a time, and shorter lists pad with empty values

The item each generated question actually used is recorded per column as <column>_actual in the results file.