Tuesday 16 April 2013

Passing variable in custom label

At a certain time, I thought it was impossible to do, then one day I came across, the way to do it, here and there. Here is the solution :
 suppose you want to add the connected user name dynamically

 1. Create the label  :

2. Now  add the label on your page like this :

<apex:page>
  <!-- Begin Default Content REMOVE THIS -->
  <h1>
      <apex:outputText value="{!$label.Hello}">
          <apex:param value="{!$user.userName}" />
      </apex:outputText>
  </h1>

  <!-- End Default Content REMOVE THIS -->
</apex:page>


There is some problem with this therefore, especially when the text in the custom label contains the ' (single quote) character . There is eventually, a way to bypass it, look at the example below :

Conformément à l'article 121 – II de la loi no. 2012-387 du 22 mars 2012, l'indemnité forfaitaire pour frais de recouvrement en cas de<br/>
40 euros par le décret no.2012-115 du 02/10/2012. Tout matériel ou logiciel reste la propriété de {0} jusqu'au paiement<br/>
Aucun escompte ne sera accordée pour paiement anticipé<br/>
'{1} au capital de {2}, No. Siren : {3}, TVA CEE : {4}


To bypass the ' (single quote)char , we use another '(single quote) in the right place, just that.

1 comment:

  1. another simpler option is to replace the single quote by the single quote equivalence in html

    ReplyDelete