About this article
This article explains what the IfElse() function is and provide examples of how it can be used with the binding syntax in smart templates.
Prerequisites
|
What is the IfElse() function?
IfElse() is a commonly used function that outputs values based on a condition. The function is commonly used with smart fields (with the binding syntax or the visibility), and can also be used with template settings and properties.
IfElse() logic
Syntax | {{IfElse(Condition, TrueValue, FalseValue)}} |
Input | Condition |
Output | TrueValue/FalseValue |
|
IfElse() function examples
- Example 1 - Set visibility based on value of a text form field
- Example 2 - Set visibility based on value of a date form field
- Example 3 - Set visibility based on value of a number form field
- Example 4 - Show specific text as output based on if it equals the value of a number form field
- Example 5 - Show specific text as output based on if it contains the value of a text form field
- Example 6 - Show specific text as output based on if it equals the value of a text form field (nested)
- Example 7 - Show specific text as output based on if it not equals the value of a text form field
- Example 8 - Set visibility based on value of a checkbox form field
- Example 9 - Set visibility based on value of checkbox form fields A and C
- Example 10 - Set visibility based on value of checkbox form fields A or C
- Example 11 - Set visibility based on value of checkbox form fields A and C (not B)
- Example 12 - Set visibility based on if user profile field contains specific value
- Example 13 - Dynamically insert text element or slide based on value of a checkbox form field
- Example 14 - Show value of text form field if HostSystem field is empty
Example 1
Using the IfElse() function to set the visibility of a smart field based on the value of the 'Subject' question originating from the response form.
Binding | {{IfElse(Equals(Form.Subject, "Test"), VisibilityType.Hidden, VisibilityType.Visible)}} | |
Input | Form.Subject = "Test" | Form.Subject = "Something else" |
Condition | True | False |
Output | Hidden text | Visible text |
Example 2
Using the IfElse() function together with FormatDateTime() to set the visibility of a smart field based on the value of the 'Date' question (of type Date
) originating from the response form.
Binding | {{IfElse(Equals(FormatDateTime(Form.Date,"d-M-yyyy"), ""), VisibilityType.Hidden, VisibilityType.Visible)}} | |
Input | Form.Date = empty | Form.Date = filled |
Condition | True | False |
Output | Hidden text | Visible text |
|
Example 3
Using the IfElse() function together with FormatNumber() to set the visibility of a smart field based on the value of the 'Number' question (of type Number
) originating from the response form.
Binding | {{IfElse(Equals(FormatNumber(Form.Number,"#"), "1"), VisibilityType.Hidden, VisibilityType.Visible)}} | |
Input | Form.Number = "1" | Form.Number = "123" |
Condition | True | False |
Output | Hidden text | Visible text |
|
Example 4
Using the IfElse() function together with FormatNumber() to set the visibility of a smart field based on the value of the 'Number' question (of type Number
) originating from the response form.
Binding | {{IfElse(Equals(FormatNumber(Form.Number,"#"), "1"), "Hello world", "The quick brown fox jumps over the lazy dog")}} | |
Input | Form.Number = "1" | Form.Number = "123" |
Condition | True | False |
Output | "Hello world" | "The quick brown fox jumps over the lazy dog" |
|
Example 5
Using the IfElse() function together with Contains() to inject specific product information in the smart template based on the 'Subject' question (of type Text
) originating from the response form.
Binding | {{IfElse(Contains(Form.Subject, "Product A"), "Product A is $100", "Pricing list available upon request")}} | |
Input | Form.Subject = "We are showcasing Product A" | Form.Subject = "We are showcasing different products" |
Condition | True | False |
Output | "Product A is $100" | "Pricing list available upon request" |
Example 6
Using the IfElse() function to show the correct salutation depending on the HostSystem value of 'Gender'.
Binding | {{IfElse(Equals(HostSystem.Gender, "M"), "Dear sir", IfElse(Equals(HostSystem.Gender, "F"), "Dear madam", "Dear sir/madam"))}} | ||
Input | HostSystem.Gender = "M" | HostSystem.Gender = "F" | HostSystem.Gender = "" |
Output | "Dear sir" | "Dear madam" | "Dear sir/madam" |
|
Example 7
Using the IfElse() function together with Not() and Equals() to inject specific product information in the smart template based on the 'Subject' question (of type Text
) originating from the response form.
Binding | {{IfElse(Not(Equals(Form.Subject, "Product A")), "Description of all other products", "Description of product A")}} | |
Input |
Form.Subject = "As you can see our products are compliant" |
Form.Subject = "Product A" |
Condition | True | False |
Output | "Description of all other products" | "Description of product A" |
Example 8
Using the IfElse() function to set the visibility of a smart field based on the value of the 'CheckboxInclude' checkbox question (of type Checkbox
) originating from the response form.
Binding | {{IfElse(Form.CheckboxInclude, VisibilityType.Visible, VisibilityType.Hidden)}} | |
Input | Form.CheckboxInclude = "☑" | Form.CheckboxInclude = "☐" |
Condition | True | False |
Output | Visible text | Hidden text |
Example 9
Using the IfElse() function together with the And() to set the visibility of a smart field based on the value of two checkbox questions originating from the response form, 'Product A' and 'Product C' must both be checked for the text to be visible.
Binding | {{IfElse(And(Form.ProductA, Form.ProductC), VisibilityType.Visible, VisibilityType.Hidden)}} | |
Input |
Form.ProductA = "☑" Form.ProductC = "☑" |
Form.ProductA = "☐" Form.ProductC = "☑" |
Condition | True | False |
Output | Visible text | Hidden text |
Example 10
Using the IfElse() function together with the Or() to set the visibility of a smart field based on the value of two checkbox questions originating from the response form, 'Product A' or 'Product C' must be checked for the text to be visible.
Binding | {{IfElse(Or(Form.ProductA, Form.ProductC), VisibilityType.Visible, VisibilityType.Hidden))}} | |
Input |
Form.ProductA = "☐" Form.ProductC = "☑" |
Form.ProductA = "☐" Form.ProductC = "☐" |
Condition | True | False |
Output | Visible text | Hidden text |
Example 11
Using the IfElse() function together with And() and Not() to set the visibility of a smart field based on the value of two checkbox questions originating from the response form, 'Product A' and 'Product C' must both be checked, and 'Product B' must be unchecked for the text to be visible.
Binding | {{IfElse(And(Form.ProductA, Not(Form.ProductB), Form.ProductC), VisibilityType.Visible, VisibilityType.Hidden))}} | |
Input |
Form.ProductA = "☑" Form.ProductB = "☐" Form.ProductC = "☑" |
Form.ProductA = "☑" Form.ProductB = "☑" Form.ProductC = "☑" |
Condition | True | False |
Output | Visible text | Hidden text |
Example 12
Using the IfElse() function together with Contains() to display or hide some text based on the value of the 'UserProfile.Office.Name' originating from the user profile.
- If the 'UserProfile.Office.Name' is 'Copenhagen' or 'Berlin', the text should be hidden.
- If the 'UserProfile.Office.Name' is anything else, the text should be shown.
Binding | {{IfElse(Contains("Copenhagen, Berlin", UserProfile.Office.Name), VisibilityType.Hidden, VisibilityType.Visible)}} | ||
Input | UserProfile.Office.Name = "Berlin" | UserProfile.Office.Name = "Copenhagen" | UserProfile.Office.Name = "Eindhoven" |
Output | Hidden text | Hidden text | Visible text |
Example 13
Using the IfElse() function to dynamically insert a text element/slide based on the value of the 'Checkbox' checkbox question (of type Checkbox
) originating from the response form.
The value '123456787654321' used in the example is the Asset Id of the text element.
Binding | {{IfElse(Form.Checkbox,"123456787654321","")}} | |
Input | Form.Checkbox = "☑" | Form.Checkbox = "☐" |
Condition | True | False |
Output | Text element/slide inserted | Text element/slide not inserted |
|
Example 14
Using the IfElse() function together with Equals() to display the value of the 'Subject' question (of type Text
) originating from the response form if the HostSystem value is empty.
Binding | {{IfElse(Equals(HostSystem.Subject, ""), Form.Subject, HostSystem.Subject)}} | |
Input | HostSystem.Subject = "", Form.Subject = "Hello world" |
HostSystem.Subject = "Invitation", Form.Subject = "Hello world" |
Condition | True | False |
Output | "Hello world" | "Invitation" |
Related articles
Comments
0 comments
Article is closed for comments.