Expand my Community achievements bar.

SOLVED

How to update content while moving page in AEM

Avatar

Level 3

Hi,

 

I have a call to action(cta) button component on a page, which has target URL pointing to parent. Now when I move that page to parent1, I want the target URL of cta should change and point to parent1.

How can I achieve that?

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @hptarora 

You can try the below approach . Read the current page in the component.Then use the below method or any other method to get the parentpath.That can be assigned to the ctapath property and attached with the targetURL.

Resource res = resolver.getResource(currentPagePath);
Page page= res.adaptTo(Page.class);
String pageTitle = page.getPageTitle();
Page parentPage = page.getParent();
String ctapath= parentPage.getPath();

 

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

Hi @hptarora 

You can try the below approach . Read the current page in the component.Then use the below method or any other method to get the parentpath.That can be assigned to the ctapath property and attached with the targetURL.

Resource res = resolver.getResource(currentPagePath);
Page page= res.adaptTo(Page.class);
String pageTitle = page.getPageTitle();
Page parentPage = page.getParent();
String ctapath= parentPage.getPath();

 

Avatar

Community Advisor

Hello @hptarora 

 

In your case the reference isn't moved, thus AEM would not adjust it. The reference is present at the location and still valid.

 

Option-1: If this button always points to parent, you should use the approach suggested by @sherinregi . Easy on authors as well. 

 

Option-2:  use the listeners/workflows to adjust these links on Page move.

 

Option-3: Create your own "Action button in Sites UI" or "Workflow" for Moving such pages and adjust links.

 


Aanchal Sikka

Avatar

Level 3

Hello @aanchal-sikka ,

I think option 2 is better. Can you provide some more insight on this solution?

Is there a way I can overlay the file which actually does this move?

Thanks

Avatar

Employee Advisor

I would strongly opt for option 1.This is by far the easiest way, both in terms of coding and also in terms of runtime performance.

 

The downsides of option 2:

  • It requires much more custom code.
  • it has a performance impact (as you need to validate potentially very large subtrees on each move operation)
  • The logic of creating the right link is not there we you would expect it (in the observation listener instead of the SlingModel backing the CTA link).

The downsides of option 3:

  • The implementation effort will be huge, and you customize the UI.
  • For the workflow: see option 2