function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MikeGinouMikeGinou 

Problems using Custom Label as Attribute default value

I am trying to use a Custom Label as the default value for a string attribute in an Apex Component, however it doesn't appear to work.

 

Given the a custom label Default_Title with a value of "Default Title" and the following component:

 

 

<apex:component>
  <apex:attribute name="title" type="String" default="{!$Label.Default_Title}" description="Title" />

  <apex:outputText value="{!title}" />
</apex:component>

 

 

What you would expect to see is "Default Title", instead what I'm getting instead is "#{$Label.Default_Title}". 

 

Any advice?

 

Thanks!

blombardisblombardis

Hi MikeGinou,

 

I tried to execute that code and I have the same problem.

What you need to do is to assign that label value throw the controller and then put in apex:attribute default that variable

MikeGinouMikeGinou

I opted to remove the default value from the attribute and use {!BLANKVALUE(title,$Label.Default_Title)} where I was referencing {!title} previously.

 

I haven't tried it, but I could probably also use the apex:variable tag, if I needed to reference the title attribute multiple times:

 

<apex:variable var="titleLabel" value="{!BLANKVALUE(title,$Label.Default_Title)}" />