4

In the markup of a lightning component I want to set this string a the value for a label-attribute:

"label {1}"

Let's take a lightning button as an example. But my question is unspecific and applies to any component and any string attribute. I also want to write it as an expression, to get the "...{1}" dynamically composed later. For the sake of simplicity I'm omitting that here.

Obviously this won't save

<lightning:button label="{! 'label {1}' }"  />   

So I've tried this

<lightning:button label="{! 'label &#123;1&#125;' }" />

But still I get an FIELD_INTEGRITY_EXCEPTION error while saving:

Cannot mix expression and literal string in attribute value, try rewriting like {!'foo' + v.bar}

This will save

<lightning:button label="{! 'label &#123;1' }" />

The only remaining problem is the &#125; which stands for a } right curly bracket. The parser is obviously recognizing the closing bracket as the end of the {!...} expression, while I want it to be part of the value.

Is there any way to feed such a right curly bracket character into an expression of an attribute value? Is there a way to escape it somehow?

  • 2
    Are you evaluating the expression? if not then you dont need {!}. And can directly use : <lightning:button label="label {1}" /> – Pranay Jaiswal Jan 29 at 17:32
  • else can you not have a string attribute and populate it via client side controller – Raul Jan 29 at 17:37
  • @PranayJaiswal : yes, I need to evaluate the expression, because as said, it will become a dynamic value in the end... – Uwe Heim Jan 29 at 19:07
  • @Raul : I know, but exactly this I would like to avoid – Uwe Heim Jan 29 at 19:08
  • 1
    @javanoob PERFECT !!! this works. Post it as answer and I will accept it. Thanks so much! – Uwe Heim Jan 30 at 15:06
4

You can replace } with unicode \u007D and it is working. I just tried.

<lightning:button label="{! 'label {1' + '\u007D'  }" />

Gives the output:

enter image description here

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.