Text Based on Prior Answers

The best way to display conditional text is by using Instruction blocks and Invisible Logic. But you can also use syntax to accomplish this. Here are a few use cases:

1. Display Message Dependent on Response to Prior Question

Use the following to say that you want Text 1 to appear if variablename is Option 1, but otherwise, you want Text 2 to appear.

${ ""Text 1"" if variablename == "Option 1" else ""Text 2"" }

Ex. ${ ""You are married"" if maritalstatus == "Married" else ""You are not married"" }

2. Display Calculations in Interview:

The sum of the numbers on the prior page is ${ FirstNumber + SecondNumber }.

3. List the sum of a repeating item attribute:

Validate and calculate the sum of a repeating item attribute by replacing the bold sections below with your own ItemName and ItemAttribute.

${ sum(item.ItemAttribute for item in ItemName) }

4. Display Message Dependent on Calculation

Display a certain message to the end-user based on a calculation. For example, the following will tell the user they don't qualify if Variable1 + Variable2 is less than 10.  Otherwise, it will tell the user they do qualify:

${ ""You do not qualify, so please stop."" if ((Variable1 + Variable2) <10) else ""You do qualify, so please proceed."" }

5. Display Date Calculations in Interview:

Display messages based on a date being too far in the past.  Ex. the following example calculates whether a date is more than 30 days in the past and displays a message if it is:

${ ""We are sorry. You are too late."" if date_difference(starting=DateVariable).days > 30 else ""Ok, great. Let's continue."" }

${ ""You made it before Christmas"" if DateVariable > as_datetime(""2020-12-25"") else ""You are late."" }

6. Longer Conditions

Display a whole set of conditional paragraphs or list of repeating item choices.

Several Paragraphs: You can also set these conditions on separate lines and add ""else"" statements for the alternative scenario, like this (indent with two spaces where you have your paragraphs):

Conditional logic in legal app questions

Like this:

% if variablename == 'Option 1':  

Your text here

% endif

Repeating Item Choices: If you want to display all of the repeating item choices a user has previously entered, you can do the following (only changing the red parts below):

% for item in ItemName:  


% endfor