Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Is there a way to change the page properties of several pages at a time?

Avatar

Level 1

Specifically I have several child pages feeding into a list component, but they are not hidden in the navigation. Rather than going to each child page and making that change to hide it in the navigation, is there a way to change the page properties en mass? Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can write a tool using the PageManager API: 

https://docs.adobe.com/docs/v5_1/cq-wcm-javadoc/com/day/cq/wcm/api/Page.html

https://docs.adobe.com/docs/v5_1/cq-wcm-javadoc/com/day/cq/wcm/api/PageManager.html

Using this API - you can automate page properties. 

Or you can use the JCR API and modify the node properties. 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

You can write a tool using the PageManager API: 

https://docs.adobe.com/docs/v5_1/cq-wcm-javadoc/com/day/cq/wcm/api/Page.html

https://docs.adobe.com/docs/v5_1/cq-wcm-javadoc/com/day/cq/wcm/api/PageManager.html

Using this API - you can automate page properties. 

Or you can use the JCR API and modify the node properties. 

Avatar

Community Advisor

Its best practice to hide it when the page is created. However, if its created in bulk as @scott mentioned, can write a quick service to do the job.

Avatar

Level 1

Do you have any example to create a tool using a API in aem? Thanks!

Avatar

Level 8

I don't know what version of AEM you're using, but this is a sightly class that on activation will do what you're requesting.

(This has not been tested to be accurate, however, i'm pretty sure it'll work assuming it's ran on the author instance as an administrator or author.  This was literally thrown together 2 minutes ago, so please only use it as an example)

package com.project.core.helpers; import com.adobe.cq.sightly.WCMUsePojo; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.PageManager; import org.apache.sling.api.resource.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Iterator; import javax.jcr.Node; import javax.jcr.Session; public class PageHelper extends WCMUsePojo { private static final Logger logger = LoggerFactory.getLogger(PageHelper.class); private String path; @Override public void activate() throws Exception { this.setPath(this.get("path", String.class)); updatePages(); } public String getPath() { return path; } public void setPath(String path) { this.path = path; } private void updatePages() { if (this.getPath() != null && !this.getPath().isEmpty()) { PageManager pageManager = this.getPageManager(); Page page = pageManager.getPage(this.getPath()); if (page != null) { Iterator<Page> children = page.listChildren(); while(children.hasNext()) { Page currentPage = children.next(); Resource contentResource = currentPage.getContentResource(); if (contentResource != null) { Node contentNode = contentResource.adaptTo(Node.class); if (contentNode != null) { try { Session session = this.getResourceResolver().adaptTo(Session.class); contentNode.setProperty("isHideInNav", true); session.save(); } catch (Exception e) { logger.error(e.getMessage()); } } } } } } } }