0

Let's say I have a modal component with a header and footer facet, like:

<aura:attribute name="header" type="Aura.component[]" />
<aura:attribute name="footer" type="Aura.component[]" />

<header>
    <h2>{! v.header }</h2>
</header>

{! v.body }

<footer>
    {! v.footer }
</footer>

Is there a way to test (or have a conditional for) if the footer has been set?

I want to be able to not show the footer (or have some default content) if the consumer (parent component) does not include a footer value.

1 Answer 1

1

Yes, aura:if plus empty() would get you there:

<aura:if isTrue="{!empty(v.footer)}">
  
  Default Content
  
  <aura:set attribute="else">
    {!v.footer}
  </aura:set>

</aura:if>

aura:if causes an extra rendering cycle, but dynamically renders its content, which can save rendering/execution time.

empty() returns true if a value is undefined, null, empty string, or an empty array.

1
  • Perfect - thanks!
    – jbyrd
    May 6, 2021 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.