Forum Discussion

santosh_csc's avatar
8 years ago

How to do Text replace in email template?

Text key looks like this.

footer={communityTitle} sent this message to {Recipient}.

Now I have to replace {communityTitle} with the name of the community which is available in the context object.

#set ($footer1=$footer.replace("communityTitle",${community.title}))
${footer1}

Above piece of code is not working.

 

Any idea why?

How can I achieve this?

 

5 Replies

  • santosh_csc's avatar
    santosh_csc
    Guide
    8 years ago

    @petelu
    Thanks for the response.
    The code which I wrote also Velocity code only.
    I have referred https://stackoverflow.com/questions/6843882/replace-a-substring-of-a-string-in-velocity-template-language to replace the string. But it's not working with text-keys.
    It's working for a local variable like below.

     

    #set ($abc="Hi Hello")
    #set ($footer1=$abc.replace("l","p"))
    ${footer1}

    Above code prints Hi Heppo which is expected. Why it's not working text keys alone. 

     

    I have verified that text-keys are not coming null inside template.

     

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    8 years ago

    Hi santosh_csc

     

    this should work:

     

    #set ($footer1 = "${footer}")
    #set ($footer1=$footer1.replace("communityTitle",$community.title))
    $footer1
  • santosh_csc's avatar
    santosh_csc
    Guide
    8 years ago

    Getting the below error when I run the above code what you have suggested.

     

    The component causing the issue is: component.content.studio-title (content). If you have recently made changes to this page or component, please use this link to be taken to the Page Editor in Studio. If this is not the case, please contact your Administrator.

     

     

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    8 years ago

    Wondering if could be related to what is in the footer text key, try to replace the {} brackets with something else...