Code By Code – Lightning Framework – Chapter 7 – Conditional Markup

Code By Code – Lightning Framework – Chapter 7 – Conditional Markup

Chapter 7

Topics for this chapter:
– Conditional Markup

Conditional Markup

Use <aura:if> component to generate conditional markup. If the expression defined in <aura:if> is True, markup will be generated, also, if the expression is false, the markup will be destroyed. Using the <aura:if> tag is the preferred approach to conditionally display markup but there are alternatives.

Using aura:if for Conditional Markup

<aura:if isTrue=”{!v.showNew}”>
<lightning:button variant=’neutral’ label=’New’ onclick=”{!c.createRecord}”/>
</aura:if>

Use JavaScript for conditional markup

You can also use javascript to conditionally generate or destroy markup.

var elem = document.getElementById(“myDiv”);
elem.parentNode.removeChild(elem);

Conditional and Logical Operators

There are multiple operators that you can use within a component markup. The operators must be used within {} in component markup. For ex, {!v.count > 10}

Conditional Operators:

  • == (eq)
  • != (ne)
  • <= (le)
  • >= (ge)
  • < (lt)
  • > (gt)

Logical Operators:

  • && (AND)
  • || (OR)
  • ! (NOT)

Lightning Component Development Day3 - App, Attributes, Looping, Conditional Markup, Handling Events

Test Your Knowledge

Conditional Markup

Next In This Guide

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Salesforce.com Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

This Post Has 2 Comments

  1. Avatar

    Hi Manish,

    In my understanding answer for below question should be false , because if condition evaluates to false then only markup will be destroyed. Please suggest.

    Does aura:if destroy component markup if the condition evaluates to true?

    1. Avatar

      Yes Vipul, Thanks for bringing this to my attention. I have changed the quiz answer.

Leave a Reply

Close Menu