How to use the if/else node
The If/Else node is very powerful and can be used to do the following:
- Ask the user a specific question, based on an answer (or combination of answers) given by the user.
- Match your products based on a calculated value using variables.
When adding an if/else node to your flow you can add "answers" to the that node, just like you can with any other question. The difference here is, that you can decide which answer/outcome should be chosen, based on conditions defined by you.
But how is this different from configuring a different follow-up question for an answer?
While you can configure a different follow-up for each answer and ask a different question based on the answer given by the user, you can only do so for that specific answer.
1. Ask the user a specific question, based on an answer (or combination of answers) given by the user.
Let's say we're selling duvets. For this, we created the following flow with questions in this specific order:
- Type (who the duvet is for)
- For which season
- Does it need a tuck-in strip
- What size
- If the duvet should be fire retardant
We have created a separate flow for our children duvet's because they are fire retardant by default and have different sizes from adult duvets. As you can see, both the season and tuck-in strip questions are exact duplicates. If we would add another type to our flow, for example, adult double bed duvets, we would again have to create a different flow, creating even more duplicates.
Eliminating duplicate questions
As you can imagine, this can get out of hand pretty quickly. For every change we make in the flow or in the data matching we'll need to do double work. Let's get rid of the duplicates in this flow with if/else nodes.
In the flow above, we've added an if/else node between the tuck-in strip and size questions. With this change, we've eliminated the duplicate season and tuck-in strip questions, saving us a bunch of work when updating our flow.
Adding and using an if/else node
To add an if/else node, simply drag the node from the bar on the right (under "Advanced") into your flow. Once you've added the node, add an answer for each possible outcome you want. In our case, we want a "Child" and "Adult" outcome.
When editing an if/else answer we can define "Conditions" required for that answer to be automatically picked. Let's take our "Child" answer for example where the condition is that this answer should only be picked if our first question is equal to "Child's duvet".
2. Match your products based on a calculated value using variables.
Instead of creating conditions based on given answers, you can also create conditions based on variables. As an example, let's create a simplified flow to determine someone's t-shirt size and only show products matching the user's size.
What we want to do here, is collect the size inputs from the "Chest width" and "Torso height" questions and use the combination of these inputs to determine the right size. Once we've done that, we can use the if/else node to automatically select the right size. Let's start by collecting the user input and storing it in a variable.
Collecting the user inputs
To do this, click the answer for the number input and go to the variables tab. Create a variable here (for example "chest_width") and check the "Use input" checkbox. Do this for each number input. Below is an example on how we do this for the "Chest width" question.
Using variables in if/else conditions
Once we've set the variables, we can use these variables in the conditions for the if/else node. Below is an example on how we do this for size "M".
Storing variables based on automatically selected if/else answers
Once we've added the conditions for each size in the if/else node, the correct size "answer" will now automatically be selected. To display the size to the user, we can save a new variable for each size answer. Below is an example on how we do this for size "M".
Showing a variable in the results text
To show the size to the user, we'll need to use this variable in the results text. We can do this by going to "Settings -> Results -> Results text" and adding the variable to the results text.
Matching the products based on the if/else outcome
Great! Last thing we'll need to do, is actually match products based on the user's size. Under "Matching -> Data matching" we can select the "Calculate size" question on the left and add the correct rules for each size/answer.
Once we've done all this, and preview our flow, we can now see that our size is correctly displayed and only t-shirts in our size are being shown!
Documentation