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!

4 Answers 4

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.

3
  • 1
    Thank you @Kristian, This is a much needed feature to effectively use Labels with less dependencies. Commented Jul 27, 2020 at 4:28
  • Hi @Kristian, where can we find the link/source for Roadmap please?. just wondering when they will be pilot/GA for customers. Commented Jul 27, 2020 at 5:40
  • Got an update from SF support that this will be in Winter 21 , added to Ideas here trailblazer.salesforce.com/ideaView?id=0874V000000M0ZqQAK Commented Jul 29, 2020 at 3:40
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")));
1
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)

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

Any update on this one? I've tried the two below and get a mixed expression error on compile....

<aura:attribute name="emailOptionList" type="List" default="[
    {'label':  {!$Label.c.All_attendees}, 'value': 'All'},
    {'label': {!$Label.c.Only_internal_attendees}, 'value': 'InternalOnly'}
]"/>

<aura:attribute name="emailOptionList" type="List" default="[
    {'label': '{!$Label.c.All_attendees}', 'value': 'All'},
    {'label': '{!$Label.c.Only_internal_attendees}', 'value': 'InternalOnly'}
]"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .