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

ย 

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๐Ÿ‘จโ€๐Ÿ’ป

Image 3


This is how we can reference the Custom Label {!๐˜“๐˜ข๐˜ฃ๐˜ฆ๐˜ญ.c.MyLabel} in Lightning App Builder

Image 1


This is how we can reference the Custom Label {!๐˜“๐˜ข๐˜ฃ๐˜ฆ๐˜ญ.c.MyLabel} in LWR Site!

Image 2


โš  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