Blocks
`- block:` is a named container that groups other flow elements — pages, loops, conditionals, even nested blocks — under one shared `if:` or `order:`. Blocks live in the flow alongside pages; they don't live inside them. Use blocks to gate a multi-page section, randomize the order of related pages, or organize a long survey into chapters.
What - block: is
A block is a named wrapper for a chunk of the flow. Three primary uses:
- Gate several pages together. Apply one
if:to a whole chapter — every page inside is shown or skipped as a unit. - Randomize a set of related pages. Use
order: randomto shuffle the children — common for rotating concept tests or brand chapters. - Organize a long survey into chapters. A block named
screening, another namedcore, another namedwrap_upmakes a long YAML readable.
Unlike pages — which contain only questions or nested pages — blocks can contain pages, loops, conditionals, other blocks, or questions directly.
- block:
id: brand_chapter
title: Brand impressions
if: QSegment.value == "engaged"
order: random
- page:
id: brand_apple
title: Apple
questions:
- qid: QAppleAware
type: single
text: Have you heard of Apple?
options:
1: Yes
2: No
- page:
id: brand_samsung
title: Samsung
questions:
- qid: QSamsungAware
type: single
text: Have you heard of Samsung?
options:
1: Yes
2: No
- page:
id: brand_sony
title: Sony
questions:
- qid: QSonyAware
type: single
text: Have you heard of Sony?
options:
1: Yes
2: No
The whole chapter is shown only for the engaged segment; the
three brand pages render in random order.
Properties
| Property | Values | Notes |
|---|---|---|
id | string | Required. Unique across the survey. |
title | string | Optional heading. Mostly used internally for navigation and logs. |
if | Python expression | Hide the whole block when the expression is falsey. See Routing. |
order | keyword or expression | Sequences the children as a unit. Keywords: fixed (default), random, randomEach, alphabetical, reverse, flip. Also accepts an expression that resolves to a list of child-block id: codes — e.g. hBlockOrder.rows to impose a stored sequence like [2, 4, 1, 3]. Each child block’s internals stay together and in defined order. See Order. |
questions | nested - qid: items | Used only when the block holds questions directly. Page / block / loop / - if: children sit at the block’s property indent without a questions: wrapper. |
What can go inside a block
| Child | Wrapped in questions:? | Meaning |
|---|---|---|
- qid: ... | Yes | A question. Useful when a small group of questions doesn’t warrant its own page. |
- page: ... | No | A nested page. The everyday case — most blocks wrap one or more pages. |
- block: ... | No | A nested block. Use for two-level chapters (e.g. one block per market, each containing pages per brand). |
- loop: ... | No | A loop inside the block. The block’s if: / order: apply around the loop. |
- if <expr>: | No | A conditional sub-tree. |
- note: | | No | Author-only comment. |
- script: blocks are not allowed inside a block. Place script blocks at the top level of the flow (or inside loops or - if: flow blocks). The contract restricts scripts from blocks deliberately — keeping the block surface focused on structural grouping rather than imperative work.Examples
Block of pages with a shared if:
- block:
id: driver_chapter
title: Driving habits
if: QDriver.selected == 1
- page:
id: driver_basics
title: Your driving
questions:
- qid: QYearsDriving
type: number
text: How many years have you been driving?
- qid: QMilesAnnual
type: number
text: Annual miles driven.
- page:
id: driver_vehicle
title: Your vehicle
questions:
- qid: QVehicleType
type: single
text: Primary vehicle type.
options:
1: Sedan
2: SUV
3: Truck
4: Other
- qid: QVehicleAge
type: number
text: Age of your primary vehicle (years).
QDriver is asked earlier on its own page. The chapter — both
inner pages — is skipped entirely for non-drivers, with one if:
doing the work.
Block with random page order
- block:
id: concept_rotation
order: random
- page:
id: concept_a
title: Concept A
questions:
- qid: QConceptA
type: gridSingle
text: How appealing is Concept A?
scale:
1: Not at all
5: Very
- page:
id: concept_b
title: Concept B
questions:
- qid: QConceptB
type: gridSingle
text: How appealing is Concept B?
scale:
1: Not at all
5: Very
- page:
id: concept_c
title: Concept C
questions:
- qid: QConceptC
type: gridSingle
text: How appealing is Concept C?
scale:
1: Not at all
5: Very
Each respondent sees the three concepts in a random page order — eliminating ordering bias on which concept they evaluate first.
Block whose children follow a stored sequence
Sometimes the rotation isn’t a free shuffle — it comes from a
pre-assigned design (six-cell Latin square, panel-provided order,
etc.). Store the sequence on a hidden question or script variable
and point order: at it.
- qid: hBlockOrder
type: openList
input.source: js
visibility: hide
required: False
# populated at entry with the respondent's assigned sequence,
# e.g. [2, 4, 1, 3]
- block:
id: concept_rotation
order: hBlockOrder.rows
- block:
id: 1
title: Concept A
questions:
- qid: QConceptA
type: gridSingle
scale:
1: Not at all
5: Very
- block:
id: 2
title: Concept B
questions:
- qid: QConceptB
type: gridSingle
scale:
1: Not at all
5: Very
- block:
id: 3
title: Concept C
questions:
- qid: QConceptC
type: gridSingle
scale:
1: Not at all
5: Very
- block:
id: 4
title: Concept D
questions:
- qid: QConceptD
type: gridSingle
scale:
1: Not at all
5: Very
Child blocks are matched by their id:. If the stored list is
[2, 4, 1, 3], the respondent sees Concept B, D, A, C — each
concept’s questions stay together and in defined order.
See the Order reference for every form
order: accepts.
Block holding questions directly (no inner page)
When the block’s children are - qid: items rather than pages, use
the questions: wrapper:
- block:
id: quick_check
if: QFastTrack.selected == 1
questions:
- qid: QQuickRating
type: single
text: Quick rating?
options:
1: Good
2: Bad
- qid: QQuickConfirm
type: single
text: Submit now?
options:
1: Yes
2: No
A block can hold questions directly without a wrapping page — but the questions then render at the position of the block in the flow, not on a discrete screen of their own. This pattern is rare; most authors prefer wrapping the questions in a page so the respondent gets a clean screen break.
Nested blocks for two-level grouping
- block:
id: market_us
title: US market
- block:
id: us_brand_apple
- page:
id: us_apple
title: Apple in the US
questions:
- qid: QUSAppleAware
type: single
text: Have you heard of Apple?
options:
1: Yes
2: No
- block:
id: us_brand_samsung
- page:
id: us_samsung
title: Samsung in the US
questions:
- qid: QUSSamsungAware
type: single
text: Have you heard of Samsung?
options:
1: Yes
2: No
Two-level chaptering — a market block containing brand sub-blocks,
each with its own page. The outer block can carry order: random
to rotate brands within the market while keeping the market
boundary fixed.