3

I have a series of custom labels on a Visualforce page. Not all of the custom labels are required for all languages.

I need to be able to set the custom label to something that will not display anything visible to the user if their language does not require anything to be displayed.

As the text of the label is required, I can't leave it blank. I've also tried just entering whitespace, but that fails validation too. I've tried setting it to  , but that markup is escaped when rendered.

Is there a way to do this without using a magic string and then deciding to render the label based on whether or not the label's text matches the magic string?

7

I managed to do this in Windows using " " (Alt+255); it appears as just a space of the non-breaking variety. You may need to consult your OS's manual to figure out how to type this character in your OS, or you can copy and paste the space from this post.

  • This does appear to be working, but has the downside of admins needing to know this 'trick'. Best answer so far however. – Chris Payne Jan 13 '17 at 20:29
  • @ChrisPayne Yeah, thinking about it, it'd be nice if they just gave us the ability to make the value optional for a given translation. – sfdcfox Jan 14 '17 at 5:11
  • 1
    Lol. OS Manual = google – Eric Jan 14 '17 at 15:58
  • That key combo doesn't seem to work if you don't have a full keyboard (e.g. a laptop keyboard). You would need to open character map and manually copy the space character and paste it into the custom label. That worked for me. – Pedram Sep 26 '17 at 18:15
  • @Pedram Depends on the keyboard. Some laptops have a Fn+NumLock button you can use, others, like mine, have a full number pad that works, and yes, in some rare systems, you'll need an external keyboard or copy-paste from character map or this answer. I personally tend to use FileFormat.info to find obscure characters to copy-paste. There's a variety of ways you can find a way. – sfdcfox Sep 26 '17 at 18:17
0

You can try out this approach:

Let's say you are assigning &nbsp to the label value.

Whether label to be displayed or not you can make a check and conditionally display that.

<apex:variable value="{!$Label.TestCustomLable}" var="myVar" />
<apex:outputLabel value="{!$Label.TestCustomLable}" rendered="{!myVar!= '&nbsp'}"/>
  • 1
    That will work but the OP specifically requested to avoid this strategy. – Adrian Larson Jan 13 '17 at 19:04
  • for my sake of understanding, can you please give some light why to avoid this stratery – Santanu Boral Jan 13 '17 at 20:12
  • 1
    It's too fragile, has the potential to cause undesired functionality (ie what if an admin actually wants to display &nbsp?), requires extra markup in the VF page, and just feels like a hack. – Chris Payne Jan 13 '17 at 20:16

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.