1

I'm trying to set Attribute Default Value from a Custom Label.

  1. I tried setting Custom Label in Attribute default Value in a Custom Component. e.g.

<aura:attribute name="attributeFromLabel" type="String" access="GLOBAL" default="{!$Label.c.Label1}"/>

This compiles without any errors. But when I add it from App Builder to a record page,etc. this appears as below.

enter image description here

Tried,

  • {!$Label.c.Label1}
  • "{!$Label.c.Label1}"

When you use exclamation in the builder it throws below permission error.

Permission error

The reason for being able to use Labels here is to use SF native Label translation effectively. It looks like we need to programatically extract Labels, and pass it across controller to markup to achieve this?

Can we use Custom labels within App Builder/Community Builder? What is the best practice to achieve this? preferably with least code changes/dependencies.

Thanks!

2

As you have noticed, this is currently not a supported feature (source: I'm on the Lightning App Builder team). Setting labels in App Builder is on the short term roadmap, but defaults looks like is further out (safe harbor).

Best option right now is to set the label programmatically in the controller, and then use the design property in the builder as a way for your users to override it.

| improve this answer | |
2

You can setup it in init method on component like this

<aura:component>
   <aura:attribute name="attributeFromLabel" type="String" access="GLOBAL" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    

    
</aura:component>

in JS

({
    doInit: function(cmp) {
        // Set the attribute value. 
      
        cmp.set("v.attributeFromLabel",$A.get("$Label.c.Label1"));
    }
})

Also if you want page attributes to pass label name then you can do this

just pass the Label name from App builder

and use the same attribute to get the label like this in init

component.set("v.WhateverAttribute",$A.get("$Label.c."+component.get("v.attributeFromLabel")));
| improve this answer | |
1

We're looking at shipping (GA) the localization support in the Lightning App Builder in Winter '21 (Safe Harbor) and as Kristian has pointed out, the design attribute defaults are on the roadmap but not yet prioritized. (I work with Kristian on the Product side)

| improve this answer | |
  • Hi @Almeen Arif Thanks for your answer, does it include the ability to use Custom Labels in App Builder? – Pasan Eeriyagama Jul 29 at 0:01
  • Got an update from support, this would be released in Winter 21. Thanks! – Pasan Eeriyagama Jul 29 at 3:39

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.