Aura if - isTrue parameter and multiple conditions

2.8K    Asked by YamamotoSaito in Salesforce , Asked on Aug 5, 2021



Answered by Fiona Dickens

Compiler is complaining about aura:if because you're using assignment (=) instead of conditional operator (==), in the second condition: (editMode='true'). Also you should know that AND function is case sensitive.

Second problem mentioned by Jayant would give a problem at run time.

You need to change:

    isTrue="{!AND(v._candidateDetails.contact.Nationalite__c != null), (editMode='true'))}"

to:

    // not should if there is a typo as attribute _candidateDetails starts with an Underscore isTrue="{!and(v._candidateDetails.contact.Nationalite__c != null), (v.editMode=='true'))}"

Your Answer

Answer (1)

In Salesforce's Aura components, the aura:if component is used to conditionally render content based on an expression. The isTrue attribute of aura:if accepts a boolean expression to determine whether the content inside should be rendered.

To handle multiple conditions, you can use logical operators (&& for AND, || for OR) within the isTrue parameter. Here’s how you can do it:

Using aura:if with Multiple Conditions

Example with AND Condition (&&)


Example with OR Condition (||)


Handling More Complex Conditions

You can also combine multiple conditions with both AND and OR logical operators. Make sure to use parentheses to group conditions correctly and ensure the logical operations are evaluated in the desired order.

Example with Complex Conditions


Practical Example

Here's a practical example that combines these concepts into a single Aura component.

Summary

  • Use && to combine conditions with a logical AND.
  • Use || to combine conditions with a logical OR.
  • Use parentheses () to group conditions and control the order of evaluation.
  • Use aura:set with the else attribute to render alternative content when the condition is false.

These examples should help you implement complex conditional rendering in your Aura components using the aura:if component.

4 Months

Interviews

Parent Categories