Is it possible to use a custom label (set to "true" or "false") to drive an aura:if condition? For instance, I want to display a banner message about upcoming maintenance. If my custom label was "MaintenanceMessage" and the value was set to "true", would this condition work?

<aura:if isTrue="{!$Label.c.MaintenanceMessage} == true">
    <c:MaintenanceBannerComponent />

And then setting the label to "false" to no longer show the message?

  • Yes, it is possible? You can also use render:if or something similar, have you tried? – glls Jul 17 '19 at 13:12
  • No, I haven't used render:if. I'll check into that, too. – Matt Smith Jul 17 '19 at 13:17
  • @glls render:if is deprecated. – Pranay Jaiswal Jul 17 '19 at 13:26
  • Sheitz, oh well. – glls Jul 17 '19 at 13:27

Yes, its possible to use a custom label in aura:if, you just have minor syntax error, following would work:

<aura:if isTrue="{!$Label.c.FirstLabel == 'your value'}">
    <c:MaintenanceBannerComponent />

Better place would be to use a custom setting instead of a label, as its much easier to manage.

  • +1 , I copied from your comment :) – Pranay Jaiswal Jul 17 '19 at 13:52
  • Thanks @Raul. I'm a bit new to this but can I reference a custom setting similar to how I'd reference a custom label? – Matt Smith Jul 17 '19 at 14:01
  • @MattSmith: if that is a hierarchial custom setting, it would be similar. Otherwise you may have to pass the value from apex class. – Raul Jul 17 '19 at 14:18

As Raul, suggested you can use something like

<aura:if isTrue="{!$Label.c.MaintenanceMessage} == 'true'}">
    <c:MaintenanceBannerComponent />

as true would be a String instead of boolean It would work, but would like to point few points.

1) Its a Custom Label , which accepts free text, thus there is big chance that a human mess things up and your logic starts breaking.

2) Also, you have consider about Multi-Language, as custom labels get translated, true /false in some other language would cause your logic to break.

A better way would be to use custom settings or metadata types.

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.