2

I'm using Custom Labels on a Visualforce page but those needs to contain a variable inside them, I'm used to it like this in Lightning:

{!format($Label.c.myLabel, v.attribute1, v.attribute2)}

Where $Label.c.myLabel has a placeholder as this: {0}, {1}.

I can't find the proper way to do it as this in a VF page.

4
  • How do you want to display the info ? {0},{1} to 0,1 ?
    – MIX DML
    Jan 11, 2017 at 10:07
  • I would like to display variable that I pass to it in place of the {0} and {1} Jan 11, 2017 at 10:12
  • You want to display info like. If {0} then display "A", if placeholder {1} then Display "B" ?
    – MIX DML
    Jan 11, 2017 at 10:24
  • No, I want to use it like I do in lightning so if my label is like "The total price is {0}" and my attribute is equal to 500 it displays to "The total price is 500" Jan 11, 2017 at 10:57

2 Answers 2

1

I am using the following way in a VF page:

<apex:outputText value="{! $Label.myLabel}">
    <apex:param value="MyParameter"/>
</apex:outputText>
0

There is a way to do that in apex controller using

String label = System.Label.myLabel;

List argList = new List();

argList.add(arg1);

argList.add(arg2);

String formatedString = String.format(label,argList);

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.