Custom Label As A Property In Lightning Page & LWR Site๐๐๐

ย
Did you know that we can use Custom labels as Property input values in Lightning App Builder
Using this format
{!$๐๐ข๐ฃ๐ฆ๐ญ.๐๐ถ๐ด๐ต๐ฐ๐ฎ๐๐ข๐ฃ๐ฆ๐ญ๐๐ข๐ฎ๐ฆ}.
Probably Yes, as we all have seen the help text on property editor in builder! ๐
But lets say what if we want to the same in an LWR Site๐ก. We can make it work by adding the default namespace(โcโ) to it and note, you dont need $ -
{!๐๐ข๐ฃ๐ฆ๐ญ.๐ฏ๐ข๐ฎ๐ฆ๐ด๐ฑ๐ข๐ค๐ฆ.๐๐ถ๐ด๐ต๐ฐ๐ฎ๐๐ข๐ฃ๐ฆ๐ญ๐๐ข๐ฎ๐ฆ}
For Eg:
{!๐๐ข๐ฃ๐ฆ๐ญ.c.MyLabel}
Where ๐๐ฒ๐๐๐๐๐ฅ is my custom label Name
Here is the custom label i have created in my developer edition org๐จโ๐ป
This is how we can reference the Custom Label {!๐๐ข๐ฃ๐ฆ๐ญ.c.MyLabel}
in Lightning App Builder
This is how we can reference the Custom Label {!๐๐ข๐ฃ๐ฆ๐ญ.c.MyLabel}
in LWR Site!
โ As mentioned above I have tried this in LWR site and its working perfectly, but not working in aura sites for reasons I am unaware ofโ๐คทโโ๏ธ
Bonus Tip ๐ฏ: You can set the default attribute of property in XML file as
{!$๐๐ข๐ฃ๐ฆ๐ญ.๐๐ถ๐ด๐ต๐ฐ๐ฎ๐๐ข๐ฃ๐ฆ๐ญ๐๐ข๐ฎ๐ฆ}
For Eg:
<๐ฑ๐ณ๐ฐ๐ฑ๐ฆ๐ณ๐ต๐บ ๐ต๐บ๐ฑ๐ฆ="๐๐ต๐ณ๐ช๐ฏ๐จ" ๐ฏ๐ข๐ฎ๐ฆ="๐ช๐ฏ๐ฑ๐ถ๐ต" ๐ญ๐ข๐ฃ๐ฆ๐ญ="๐๐ฏ๐ฑ๐ถ๐ต๐๐ฆ๐น๐ต" ๐ฅ๐ฆ๐ง๐ข๐ถ๐ญ๐ต={!$๐๐ข๐ฃ๐ฆ๐ญ.๐๐บ๐๐ข๐ฃ๐ฆ๐ญ}" />
Where ๐๐ฒ๐๐๐๐๐ฅ is my Custom Label Name
This way the value stored in Custom label is taken as default value and you donโt have to change this in code each and every time!๐
You can find the code for LWC components used in my github repo
- LWC Component Name : labelInputComponent
This Content was originally posted in linkedin View Post