Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Search and Replace Text string

Avatar

Level 4
Level 4

Hi All, 

We need to replace a specific text string, such as "Hello World," with "Greetings, Earthlings!" on approximately 2000 pages, text string is part of content fragment, What would be the best approach to accomplish this in AEM?

 

TIA.. 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

There are various ways to accomplish this. You can write a server or script to do this. You can also use groovy script as well as sling pipes. All the above will help you in automation 

View solution in original post

8 Replies

Avatar

Level 2

Hi, 

Kindly refer to find and replace here . Also, check out this tool.

Avatar

Community Advisor

I suggest you write a custom servlet to find all content fragments under a specific path where it will find all instances of Hello World, replaces the word with Greetings, Earthlings!, and then it republishes all content fragments if they are already replicated; If content fragments are not yet activated, do nothing. Your servlet should also have a "mode=dry run" mode where it will just return you a list of all affected content fragments before the actually replace. 

Avatar

Correct answer by
Community Advisor

There are various ways to accomplish this. You can write a server or script to do this. You can also use groovy script as well as sling pipes. All the above will help you in automation 

Avatar

Level 2

Is this not inefficient and a bit dangerous having everyone write a script / servlet that wants what is basic functionality?

 

I'd like to have search and replace across my library of content fragments but to write it myself seems a bit poor?

Avatar

Community Advisor

Aem doesn’t provide you any ootb functionality that provides search and replace for the content. Atleast I am not aware of this. If you don’t want to write any type of automation then you can go with something called school way of creating a package of your content fragment and do a search and replace in the package directory after extraction using some ID and then making the package again and deploying it on aem. That’s the non-technical way I can think of without writing any automation (script/servlet)

Avatar

Level 3

Agreed @AEM_PARTY !

 

Content authoring Search and Replace just feels like something that should be available in a high-end, advanced tool like AEM without developers writing a script. A rudimentary version of it exists in the classic UI, but was never re-created in Standard (touch) UI.

Some use cases:

  • Let's say we change our company name from "Widgets R Us" to "Gizmos Inc". We want to replace on any page or fragment.
  • We have common links to a related site that is external to AEM - myaccount.widgetsrus.com and we are changing it to myaccount.gizmos.com. Everywhere it exists it needs to be changed.
  • We have used a phrase we want to change everywhere like "blacklist" to "deny list".

Maybe this is an opportunity for an AEM Commons tool?

It should:

  1. Find a word or phrase for a specified path (and children) in the repository.
  2. Replace that word or phrase with whatever is specified
  3. Optionally publish the changed content

Maybe someday!

Avatar

Level 2

Couldn't agree more and that is pretty much my use case. A product name changes and we have to manually go through hundreds of CFs updating them.

Avatar

Level 5

Hi Team, please find below my blog post for Global find and replace text.

find and Replace Text in AEMasCS