Skip to main content
Dynamic texts: Conditionals (Advanced)
Derek avatar
Written by Derek
Updated over 2 years ago

As we saw in the previous article, we can add a condition with references to display one sentence or another depending on the answer.

💡 What are references? If you want to know more, check out the following link.

In this article, we will explain in more detail how these conditions work and how you can customize them.

Understanding what delimiters do

Conditionals in Parallel work with delimiters that tell the text what to do.

{% if food == "sweet" %}
We have this amazing carrot cake for you!
...
{% endif %}

All conditionals start with this delimiter:

{% if ... %}

And they end up with this one:

{% endif %}

With the if delimiter we are evaluating a condition that, if met, we want the indicated content to be displayed.

In the example we are indicating that if (if) the food reference is equal (==) to the value sweet ("sweet") we want it to display the content that is between the delimiters, i.e., "We have this amazing carrot cake for you!"

There is a second delimiter that evaluates another condition:

{% elsif ... %}

The delimiter elsif is short for "else if" and is used to tell the text to evaluate another condition if the first one is not met. If this second condition is met, the text will display the content between this delimiter and the endif delimiter.

This delimiter is very useful to evaluate which texts display according to different possible values on the same variable or reference. Otherwise, we would have to close the conditionals with endif as many times as different values we are evaluating.

List of delimiters

Below we list the conditional delimiters and explain with the following example to see in which cases they are activated.

{% if reference == "A" %}
You have chosen A.
{% elsif reference == "B" %}
You have chosen B.
{% else %}
You have not chosen any known option.
{% endif %}

  • if: is included at the beginning of the condition.

    {% if reference == "A" %}
    You have chosen A.

    Following the example, if the answer of the reference is A, this condition will be activated and will show the text “You have chosen A.”

    When this condition is activated, all other conditions will no longer be evaluated and no further text will be displayed.

  • elsif: optional.

    {% elsif reference == "B" %}
    You have chosen B.

    Following the example, if the answer of the reference is B, the first condition will not be activated. The conditional will evaluate the next condition, which being B the reference value will evaluate as true and display the text “You have chosen B.”

    When this condition is activated, all other conditions that follow will no longer be evaluated and no further text will be displayed.

  • else: optional.

    With this delimiter, you do not need to include any expression to evaluate. We will use it when we want the dynamic text to display a content, as long as none of the previous conditions in the if or elsif have been met.

    {% else %}
    You have not chosen any known option.

    Following the example, if the reference response is other than A or B, none of the above conditions will be triggered.

    Since else evaluates for all other cases not foreseen above, the text “You have not chosen any known options” will be displayed.

    Note: This condition must always be used at the end, before the endif delimiter.

  • endif: is included at the end of the condition.

    This delimiter does not evaluate any condition, but is necessary to delimit where the conditional ends and the text that can be displayed.

    {% endif %}

Equality operators

  • == (equal to)

    This operator evaluates if what is on the left (the reference) is equal to what is on the right (the value we want to compare).

    If they are equal, the condition evaluates as true and the content inside the condition will be displayed. Otherwise, nothing will be displayed.

  • != (not equal to)

    This operator evaluates if what is on the left (the reference) is different from what is on the right (the value we want to compare).

    If both sides of the operator are different, the condition evaluates as true and the content inside the condition will be displayed. If they are the same, the condition evaluates to false and the contents will not be displayed.

Query field information with options

It is common to use select fields or multiple choice when designing templates if we want to include a set of default values, since it facilitates the automation of possibilities that we know in advance.

Therefore, if you work with any of the above fields, you will have to use the reference followed by the text "[0]" in order to access the selected option.

Let's see it with the following example where we have changed the field type from text to options:

To keep the conditionals from before working, let's add the text string "[0]" immediately after the reference: food[0]

If you have done it correctly, when previewing the dynamic text will change according to the option you choose:

Continue learning about dynamic texts

Now that you have learned how to generate dynamic texts, we encourage you to continue learning and enhance your processes with the following guides:

  • Basic formulas with text responses: Choose if you want your references to be copied and pasted with uppercase, lowercase, etc...

  • Formulas for questions with multiple answers: If for a question there is more than one answer, automatically configure how these answers will be displayed (together, separated, listed...).

  • Formulas for numerical fields: You can copy and paste numbers in different formats and choose formulas to make calculations with them.

Did this answer your question?