Forum Discussion

tagged-leo's avatar
13 years ago

Replace Text In Messages & Forums

I have a very specific use case which requires a replacing a specific keyword in message threads. 

 

For example, in the message list component, I can see all the responses users posted.  Within these posts, I am look for a keyword to be replaced. For example, if a user typed in the word 'Facebook' or hyperlinked this, I'd like to replace it with 'Social Network.' 

 

I thought I could do this with Freemarker by replacing the meesages list component but it doesn't seem to work.  Any help is greatly appreciate.  Thanks!

5 Replies

  • BrianO's avatar
    BrianO
    Lithium Alumni (Retired)
    13 years ago

    This can be accomplished by setting up a content filter and setting the behavior to "replace". Whenever a keyword is matched, it will be replaced with the term you have chosen.

     

    Community Admin > Mod Tools > Content Filters

     

    One word of best practices advice here - make sure that you message to users why you are forcing the replacements. It can be frustrating to submit a post and then see that the content has magically been changed.

  • Okay - one more detail here.

     

    I have two CNAME'd URLs pointing to the same Lithium Community. Here they are:

     

    http://help.tagged.com & http://help.hi5.com

     

    The additional logic I need to put in there is:

     

    If servername = help.tagged.com, replace all instances of 'hi5' to 'tagged'

     

    Else if servername = help.hi5.com, replace all instance of 'tagged' to 'hi5'

     

    Is this doable using content filters?

  • BrianO's avatar
    BrianO
    Lithium Alumni (Retired)
    13 years ago

    As far as I know, we do not have the ability for a filter to use CNAME as a parameter as you have described.

  • AdamN's avatar
    AdamN
    Khoros Oracle
    13 years ago

    Hi Leo,

     

    If you wanted to purely use freemarker, there may a few different standard components you'd have to replace depending on to what extent you wanted to make replacements. I think the key one would be the message body (via the Forum Message Page). You'd have to use the env context object to get the message id of the message you're rendering, then make a REST API call to get the message body. Then you'd need to use the http.request context object to determine what the current hostname is, in conjunction with the freemarker replace built in to swap the text.

     

    If you're just interested in replacing links, jQuery would make it pretty straightforward to do that on the fly.

  • Thanks Adam.  jQuery may be the way to go; I'm just afraid that the user may see some strange flicker during the page load.  I'll report once we have something working.