How can I create a groovy script to add pages under a node using same template?

zameer_abbas

13-10-2020

Using one of my editable template, is there any way where I can create n-number of pages using any groovy script or any other script? 

AEM 6.5.5.0 content groovy page

Accepted Solutions (0)

Answers (1)

Answers (1)

Manjunathh

13-10-2020

Hi @zameer_abbas 

You can create pages under specific rootPath using editable templates by below mentioned groovy script.

 

def rootPagePath = "/content/we-retail/us/en/equipment/";
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);


for(int index=0; index < 5; index++){
pageManager.create(rootPagePath,"test"+index,"/conf/we-retail/settings/wcm/templates/content-page","Test Page Title"+index);
}

 

 

Groovy console successful execution of code :

groovy-console.png

 

 

Pages created after executing script :

pages.png

 

 

-Manjunath