Logic & flow

Piping

`{{ ... }}` substitutes a runtime value into displayed text — the same template syntax you'd recognise from Handlebars / Jinja / Liquid. Inject a respondent's name into a follow-up's text, count their picks in an instruction, render the current loop iteration's label, do quick arithmetic. Works in `text:`, `title:`, `instruction:` directly.

The basic syntax

Wrap any expression in {{ }} inside a question’s text fields and the runtime substitutes its value at render time.

- qid: QFollow
    type: open
    text: Tell us more about {{ QBrand.selectedLabel }}.

When the respondent picks Samsung at QBrand, they see:

Tell us more about Samsung.

The expression inside {{ }} is the same Python subset used in Routing conditions and Validation blocks — accessors, methods, built-ins.

Where piping works

Piping is always on in any text field that the respondent might see. The everyday targets:

FieldPipe-aware?
text:Yes
title:Yes
instruction:Yes
Option label:Yes (use sparingly — see Piping in option labels)
Row label: on grids and listsYes

Just write {{ ... }} inside the text and it resolves at render time.

What to put inside {{ }}

Anything that resolves to a string-coercible value:

text: |
    Hi {{ QName.value }}, you said you've used {{ QBrand.selected.size }} brands.

Common patterns:

ExpressionRenders
{{ QBrand.selectedLabel }}Label of a single answer
{{ QBrand.value }}The raw value (code as string for single)
{{ QBrand.selected.size }}Count of selections
{{ QAge.value + 1 }}Arithmetic
{{ brand_loop.selectedLabel }}Current loop iteration’s label
{{ QSat.row(2).selectedLabel }}A row’s label inside a grid

The runtime handles type coercion automatically — numbers, labels, codes all stringify cleanly.

Piping in option labels

Option labels are pipe-aware — drop {{ ... }} anywhere inside the label text and it resolves at render time. A common pattern: carry a brand or store name forward into the label of a follow-up question.

- qid: QFav
    type: single
    options:
        1: I prefer {{ QBrand.selectedLabel }}
        2: I prefer something else
        3: I have no preference

If the respondent picked Samsung at QBrand, option 1 reads “I prefer Samsung”.

The same works on row labels for gridSingle / gridMulti / numberList / openList and anywhere else a label appears.

For larger transformations — when the set of options should change based on previous answers, not just the label text — build the list with options.from: instead. See Masking.

Piping in scale labels

The same applies to grid scale labels — {{ ... }} resolves inside any scale label, so the column headers on a grid can reflect a previous answer.

- qid: QBrandFit
    type: gridSingle
    text: How well does each attribute describe {{ QBrand.selectedLabel }}?
    options: brandAttributes
    scale:
        1: Doesn't describe {{ QBrand.selectedLabel }} at all
        2: Describes {{ QBrand.selectedLabel }} a little
        3: Describes {{ QBrand.selectedLabel }} well
        4: Describes {{ QBrand.selectedLabel }} perfectly

Both the question text and the scale labels substitute the selected brand. If QBrand.selectedLabel resolves to Samsung, column 3 reads “Describes Samsung well”.

Reusable scale lists defined under - scales: are pipe-aware the same way — the substitution happens at render time, after the scale is resolved.

Inside loops

Loop accessors are the most common piping target. The loop variable named after the loop’s id exposes the current iteration’s label and value.

- lists:
    brandList:
        1: Apple
        2: Samsung
        3: Sony
        4: LG

- qid: QBrand
    type: multi
    text: Which brands have you used in the last year?
    options: brandList

- loop:
    id: brand_loop
    options: brandList
    options.from: QBrand.selected
    - qid: QRating
        type: number
        text: Rate {{ brand_loop.selectedLabel }} out of 10.
        min: 0
        max: 10

    - qid: QWhy
        type: open
        text: Why did you give {{ brand_loop.selectedLabel }} that rating?

Each iteration renders with the iteration’s label substituted in. See Loops for the full loop-variable surface.

Conditional piping

Use a Python conditional expression inline:

text: |
    Hi {{ "there" if not QName.answered else QName.value }}, welcome back.

For more elaborate conditional rendering, prefer two distinct questions with if: rather than complex piping logic.

Piping into HTML

Text fields can contain HTML markup from the Safe HTML allow-list. Piped values are HTML-escaped automatically before they’re inserted, so a respondent’s typed answer can’t break out of the template into raw markup.

- qid: QGreeting
    type: info
    text: |
        Welcome back, <b>{{ QName.value }}</b>! You last visited
        on <i>{{ QLastSeen.value }}</i> and your status is
        <u>{{ QStatus.selectedLabel }}</u>.

<b> for bold, <i> for italic, <u> for underline — the three tags you’ll reach for most often inside piped text. All three sit in the Safe HTML allow-list alongside <strong>, <em>, and the rest.

Even if a respondent typed <script>alert(1)</script> into QName, the rendered output is the literal string with < and > escaped — not an executed tag.

This means you can pipe any answer (including free open text) into HTML contexts without writing your own escaping.

Format helpers

Standard Python formatting works inside {{ }}:

text: Your spend is {{ "%.2f" % QSpend.value }} per month.
text: That's {{ round(QPercent.value * 100) }}%.

For string concatenation:

text: |
    Total: {{ str(QA.value + QB.value) }}.

Piping inside fail() and print()

Messages passed to the runtime helpers fail(...) and print(...) are pipe-aware too. Drop a {{ ... }} placeholder anywhere in the string and it resolves the same way as in text:.

- qid: QAlloc
    type: numberList
    text: Allocate 100 points across these categories.
    options: spendCategories
    validation: |
        total = 0
        for c in QAlloc.all:
            total = total + (QAlloc.row(c).value or 0)
        if total != 100:
            fail("Allocations must sum to 100. You have {{ total }}.")

When the respondent’s allocations sum to 87, they see:

Allocations must sum to 100. You have 87.

{{ total }} references the local Python variable computed inside the validation: block. Cleaner than string concatenation — compare against "You have " + str(total) + ".".

The same works for print(...) in scripts, useful in Test-assist mode for surfacing intermediate values:

- script: |
    segment = "premium" if QSpend.value > 100 else "standard"
    print("Assigned segment: {{ segment }} (spend = {{ QSpend.value }})")

Anything in scope when the helper runs — local variables, hidden question values, Q.* accessors — is available inside {{ }}.

See also

  • Routing — if: conditions use the same expression syntax
  • Validation — validation: blocks use the same accessor surface
  • Loops — the loop_id.selectedLabel pattern is the most common piping use
  • Q.* accessors — every accessor that’s pipe-friendly
  • Safe HTML — the allow-list for HTML markup in text fields