Response piping is used to customize a respondent's survey experience by inserting a previous question's response into a subsequent question or location. For a question QX, use $QX_text
to pipe its response text. To pipe the response ID of a closed-ended question, use $QX
.
setlist: STORES
1345. Safeway
8452. Kroger
2364. Trader Joe's
4890. Whole Foods
9764. Publix
5. Which is your favorite grocery store?
type: radio
optsfrom: STORES
showtext: FAV_STORE
text: The option id for <b>$Q5_text</b> is <b>$Q5</b>.
Tip! For more information about piping, see get_answer. For information about piping questions into other locations, see Question piping.
Details
- Use
$QX_text
to pipe in option text for closed-end questions or inputted responses for open-end questions. While both$QX
and$QX_text
work for open-end responses,$QX_text
is recommended. - Multiselect checkbox and listbox questions can store multiple values in a single question or variable. If multiple responses are selected, they will be piped in a comma-separated list.
- If an autoother option is selected, the inputted text will be piped for the text placeholder, instead of the original option text (e.g., 'Other').
-
Loops have their own piping placeholders they use for the lists they iterate over. To reference option text, use
~text~
. To reference an option ID, use~id~
. These placeholders are not case sensitive. - Similarly, blocks also have their own piping placeholders they use for the lists they iterate over. To reference option text, use
%%TEXT%%
. To reference an option ID, use%%ID%%
. These placeholders are not case sensitive. - Perl can also be used for more advanced piping needs.
Additional examples
Piping multiselect question responses
When a multiselect question is referenced via a '_text' reference, the system automatically employs the get_answer
helper method. If multiple options are selected, the text for each option will be listed, separated by commas.
For example, if a respondent selected Brand 1 and Brand 3, the $Q6_text
placeholder would be replaced with "Brand 1, Brand 3" in Q7.
6. Which of these brands have you ever used?
type: checkbox
1. Brand 1
2. Brand 2
3. Brand 3
4. Brand 4
7. What do you think of $Q6_text?
type: textbox
Tip! To add a final joining word ("and") to a multiselect response, you can use a Perl join
function or the get_phrase
method.
Piping "other" responses
Autoother options create text fields where respondents can provide their own option. If the autoother response is selected, its original option text will not be piped in a '_text' reference, but rather the inputted respondent text.
For example, if "Publix" was entered for option 97 in Q8 below, 'Publix' would be piped into Q9, not 'Other'.
setlist: STORELIST2
1345. Safeway
8452. Kroger
2364. Costco
4890. Jewel/Osco
97. Other {autoother: y; placeholder: specify; size: 10}
8. Which is your favorite grocery store?
type: radio
optsfrom: STORELIST2
9. How many times have you shopped at $Q8_text in the past month?
type: integer
size: 3
range: 0-31
postfix: times
Piping in loops
Loops have their own placeholders for piping option text and IDs from their iterating lists. The ~text~
placeholder functions similarly to $QX_text
so that the looped content will display an option's text in each question for that iteration. For option IDs, use ~id~
.
The loopfor
tag specifies which list the loop should iterate over. In the example below, Q11 uses question label syntax, indicating it should repeat for each option selected in Q10 from the SHOES list.
setlist: SHOES
1. adidas
2. Nike
3. Puma
4. Sketchers
5. Under Armor
97. Other {autoother: y; size: 8}
10. Which of these shoe brands have you owned previously?
type: checkbox
optsfrom: SHOES
11. Do you currently own a pair of ~text~?
type: radio
loop for: Q10
1. Yes, just one pair
2. Yes, multiple pairs
3. No, not any more
Piping in blocks
Like loops, blocks have their own specialized placeholders for piping option text and IDs from their iterating list. A double percent sign is used for its text and ID placeholders — e.g., %%TEXT%%
and %%ID%%
.
In the example below, Q4C%%ID%% iterates over the Q3C list (the options selected in Q3C). It uses the '%%ID%%' placeholder on it's question ID to indicate its iterations (Q4C1345, Q4C8452, etc.). The option text is then piped into each iteration for the options selected at Q3C.
setlist: STORELIST4
1345. Safeway
8452. Kroger
2364. Trader Joe's
4890. Whole Foods
3C. At which of these stores have you ever shopped?
type: checkbox
optsfrom: STORELIST4
block:<<END
4C%%ID%%. How many times have you shopped at %%TEXT%% in the past month?
type: integer
size: 3
range: 0-31
postfix: times
END
list: Q3C
Tip! Nested blocks (blocks within blocks) require a sigil for their piping placeholders instead of the '%%' before and after 'TEXT' and 'ID'. See Blocks for examples.
Advanced piping tips
If the simple text piping method shown above and get_answer
do not fit your needs, try incorporating Perl.
To create a Perl expression, place the code within square brackets with asterisks [* *]
( "Perl brackets"). This protects your code from any text or characters around the variable.
Some examples of using Perl brackets for piping include:
- pluralizing piped text by adding an 's' after the brackets — e.g.,
How many [* $QX_text *]s are there in your area?
- using a Perl
join
function for responses to multiselect questions to include a joining word between selections such as 'and' — e.g.,You said you shop at [* join(' and ', @$QX_text) *].
- using the
countChecked
function to indicate the number of options selected in a previous question — e.g.,You said you use [* countChecked($Q6) *] brand(s).
.
Comments
0 comments
Please sign in to leave a comment.