Use answers from previous questions (piping)

Use answers from previous questions (piping)

Piping means inserting a participant's earlier answer into the text of a later question — for example, greeting them by name or referring back to a choice they made. In LimeSurvey, you do this by giving the earlier question a question code and then referencing that code in curly brackets.

The recipe

  1. Assign a question code to the source question. Open the question, and in the Question settings panel on the right (Advanced tab), set the Question code field (e.g. name instead of the default Q001).
    • Codes must be unique within the survey and must not start with a number — use q1, not 1.
    • The code also becomes the variable name when you export data to SPSS or R, so short and meaningful is best.
  2. Reference it in a later question. In the text of any later question, type the code in curly brackets: {name}. When participants complete the survey, {name} is replaced with their answer.

That's it — no extra setup or activation needed. If the reference shows up literally as {name} in the survey, double-check that the code matches exactly (codes are case-sensitive) and that the source question comes before the one referencing it.

Tip: for questions with predefined answer options, {QCODE} inserts the answer code (e.g. Y). To show the answer text the participant saw (e.g. "Yes"), use {QCODE.shown}.

Example 1: greet the participant by name

  1. Question 1 — Short free text, code name, text: "What is your first name?"
  2. Question 2 — code age, text: "Nice to meet you, {name}! How old are you?"

A participant who typed "Maria" sees: "Nice to meet you, Maria! How old are you?"

Example 2: refer back to a choice

  1. Question 1 — List (radio), code product, asking which product the participant uses.
  2. Question 2 — text: "How satisfied are you with {product.shown}?"

If they picked "Cloud Backup", the follow-up reads: "How satisfied are you with Cloud Backup?"

You can also vary the wording with a simple condition. For example, if an earlier question has the code age, then {if(age < 18, 'your parents', 'you')} shows "your parents" when the participant answered under 18, and "you" otherwise. This is the same expression syntax used by the Condition designer ("New logic" in the Question settings panel).

Check that it works

Use Preview survey (the eye icon at the top right, next to Activate) to open the survey, answer the source question, then move to the page with the reference — the placeholder should show your answer. The reference only resolves in a running survey: it needs a participant's answer, so while you edit the question text on the canvas the placeholder stays as literal {name}.

Note that piping across questions on the same page updates live as the participant types; references to answers from previous pages are filled in when the page loads.

If you used the classic editor

The classic editor has a "lime between brackets" wizard button, which inserts references from a select box. In the new editor, the text toolbar's menu has a Placeholder fields entry — but it inserts participant and survey fields (name, email, survey ID and so on), not answers to previous questions. To pipe an answer, type the {code} reference directly into the question text.

Going further

Piping is the simplest use of LimeSurvey's expression engine. The same {...} syntax supports calculations, conditional text, validation, and much more — see the full ExpressionScript reference in the LimeSurvey manual.