About this article
This article will explain what the IfElse() function is and provide examples of how it can be utilized 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 utilized with template settings and properties.
IfElse() logic
Syntax | {{IfElse(Condition, TrueValue, FalseValue)}} |
Input | Condition |
Output | TrueValue/FalseValue |
|
IfElse() function examples
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 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 Contains() to inject specific product information in the smart template based on the "Subject" question 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 4
Using the IfElse() function to set the visibility of a smart field based on the value of the "CheckboxInclude" checkbox question 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 5
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 6
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 7
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 8
Using the IfElse() function to show the correct salutation depending on the HostSystem value of "Gender".
Binding | {{IfElse(Equals(Form.Gender, "M"), "Dear sir", IfElse(Equals(Form.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 9
Using the IfElse() function to dynamically insert a text element/slide based on the value of the "Checkbox" checkbox question originating from the response form.
In the example, "123456787654321" is an Asset Id
Binding | {{IfElse(Form.Checkbox,"123456787654321","")}} | |
Input |
Form.Checkbox = "☑" |
Form.Checkbox = "☐" |
Condition | True | False |
Output | Text element/slide inserted | Text element/slide not inserted |
|
Example 10
Using the IfElse() function together with Not() and Equals() to inject specific product information in the smart template based on the "Subject" question 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 11
Using the IfElse() function together with Contains() to display or hide some text based on the value of the "Office.Name" originating from the user profile.
- If the "Office.Name" is "Copenhagen" or "Berlin", the text should be hidden
- If the "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 12
Using the IfElse() function together with Equals() to display the value of the "Subject" question 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.