Expand my Community achievements bar.

How to rename a page with many references?

Avatar

Level 1

Hi,

 

I want to rename a page, but it occurs a warning as following. How can I rename this page? Thanks!

Dorothy007_1-1697600253595.png

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

8 Replies

Avatar

Community Advisor

I would recommend to use Sling Alias (Advanced Tab) property in the page properties instead of rename the page.

The property sling:alias set on any pages to indicate an alias name for the page. For example, /content/visitors may have the sling:alias property set to besucher allowing the page to be addressed in an URL as /content/besucher as well as the original path /content/visitors.

Avatar

Level 1

Thanks for your suggestion. In this case, I created a new page (using the new template ) to replace the old template page, using the same path, so I need to rename the old page to another url, failed actually. Is there any way to achieve it?Thanks.

Avatar

Community Advisor

Hi @Dorothy007 

 

It will automatically adjust name in references.You can try on one dummy page in local instance.

 

alternative, can try @Mahedi_Sabuj solution as well.

 

Hope it helps.

Avatar

Level 1

Tried. After the warning, I can't proceed the next step.

Avatar

Administrator

@Dorothy007 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Level 1

Thanks. I haven't found a solution yet. I tried both ways below and failed.

1. Rename the page: Warning the page has more than 150 references and cannot move to next step.

2. Delete the page: The page is deleted and disappeared from the content tree, but the page URL is still live. I cannot create or rename the new page with the URL name which I have deleted.

 

Do you have any recommend?Thanks in advance.

Avatar

Level 3

We can use a Groovy script to rename a page and find its references. Recently we did for some other purpose like DM migration

Avatar

Administrator

Renaming a page with more than 150 references in Adobe AEM can be challenging due to the limitations of the default rename functionality. However, there are a couple of workarounds that can be implemented to successfully rename the page and update all its references.

Method 1: Utilizing the Touch UI

The Touch UI in Adobe AEM offers a more advanced rename feature that can handle a larger number of references. To utilize this method, follow these steps:

  1. Access the Touch UI: Navigate to the page you want to rename and switch to the Touch UI mode.

  2. Initiate the rename process: Right-click on the page in the content tree and select "Rename" from the context menu.

  3. Enter the new page name: Provide the desired new name for the page.

  4. Acknowledge the warning: A warning message will appear indicating the high number of references. Click on "Rename" to proceed.

  5. Confirm the rename: The Touch UI will automatically update all references to the page, even if there are more than 150.

What happens when you do this?

 

Method 2: Use a Groovy Script

Here is an example of a Groovy script that can be used to rename a page in Adobe AEM and update all its references:

import com.day.cq.wcm.api.PageManager
import com.day.cq.wcm.api.WCMException
import org.apache.sling.api.resource.ResourceResolver

// Get the current resource resolver
def resourceResolver = scriptBindings.getResourceResolver()

// Get the PageManager instance
def pageManager = resourceResolver.adaptTo(PageManager.class)

// Get the page to be renamed
def page = pageManager.getPage("/content/my-page") // Replace "/content/my-page" with the path to the page you want to rename

// Get the new page name
def newPageName = "new-page-name" // Change "new-page-name" to the desired new name for the page

// Rename the page
page.rename(newPageName)

// Update all references to the page
def references = page.getReferences()
for (reference in references) {
    def referencingPage = pageManager.getPage(reference.path)
    referencingPage.getProperties().put("cq:name", newPageName)
    referencingPage.update()
}

// Save the changes
page.commit()

This script will rename the page /content/my-page to a new-page-name and update all references to the page. Make sure to replace /content/my-page with the path to the page you want to rename and new-page-name with the desired new name for the page.

 

Additional Considerations:

  • Backup: Before attempting to rename the page, it's crucial to create a backup of the AEM content repository to ensure data integrity in case of any unforeseen issues.

  • Testing: If the Touch UI or script method is being used, it's advisable to test the renaming process on a staging environment before applying it to the production environment.



Kautuk Sahni