Is there a way to change the page properties of several pages at a time? | Community
Skip to main content
yansanl82664461
New Participant
December 14, 2015
Solved

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

  • December 14, 2015
  • 4 replies
  • 2462 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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. 

4 replies

New Participant
December 15, 2015

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()); } } } } } } } }
yansanl82664461
New Participant
December 14, 2015

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

Lokesh_Shivalingaiah
New Participant
December 14, 2015

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.

smacdonald2008
smacdonald2008Accepted solution
New Participant
December 14, 2015

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.