Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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? 

Topics

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

6.5
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Once you click on Bindings tab in Groovy console then you will be seeing list of binding variables as shown below -

 

DEBAL_DAS_0-1651851763404.png

These are implicit objects , we don't need to create these objects explicitly to use in any script and these are ready to use.

 

I am using the similar script as given by @Manjunath_K 

def rootPagePath = "/content/we-retail/language-masters/en/equipment";

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

After successful execution -

DEBAL_DAS_1-1651851965491.png

pages were created as shown below -

 

DEBAL_DAS_2-1651852060013.png

 

Executed on AEM 6.5.11. Please try and let us know.

 

 

View solution in original post

3 Replies

Avatar

Level 8

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

Avatar

Level 1

Hi @Manjunath_K ,

While running your code I am, getting this error:- 

"groovy.lang.MissingPropertyException: No such property: PageManagaer for class: Script1"

Can you please provide any solution for this? 

Avatar

Correct answer by
Employee Advisor

Once you click on Bindings tab in Groovy console then you will be seeing list of binding variables as shown below -

 

DEBAL_DAS_0-1651851763404.png

These are implicit objects , we don't need to create these objects explicitly to use in any script and these are ready to use.

 

I am using the similar script as given by @Manjunath_K 

def rootPagePath = "/content/we-retail/language-masters/en/equipment";

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

After successful execution -

DEBAL_DAS_1-1651851965491.png

pages were created as shown below -

 

DEBAL_DAS_2-1651852060013.png

 

Executed on AEM 6.5.11. Please try and let us know.