AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle

inheritedpageproperties helps you retrieve a parent property from parent pages. Inherited page properties utilises com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap, where the search is made on the page hierarchy, upwards; searching children of the page nodes (components) are not included. Inherited page properties can be retrieved in multiple ways, where this article will only focus on 3 ways.

In this article, we will go through the 3 different ways in how we can retrieve inherited page properties.

  1. How does this work?
  2. inheritedPageProperties with Sightly
  3. inheritedPageProperties with JSP
  4. inheritedPageProperties with OSGI Bundle, Java Backend

How does this work?

An InheritanceValueMap for a given Resource that will inherit values from ancestral pages.
For example, given: /content/parent/page/jcr:content/footer/image/@width, the HierarchyNodeInheritanceValueMap will search for a footer/image/@width property in:

look up one: /content/parent/currentPage/jcr:content/footer/image/@width
look up two: /content/parent/jcr:content/footer/image/@width
look up three: /content/jcr:content/footer/image/@width


1. inheritedPageProperties with Sightly

Sightly offers a plethora of AEM Global objects, and one of them notably is the “inheritedPageProperties”. Utilising the inheritedPageProperties global object, we can use dot or square bracket notation to access the interited page property value.

1
2
3
4
${inheritedPageProperties.myCustomProperty}
${inheritedPageProperties['myCustomProperty']}
${inheritedPageProperties.jcr:title}
${inheritedPageProperties['jcr:title']}




2. inheritedPageProperties with JSP

Utilising the JSP include, /libs/foundation/global.jsp (purpose of retreiving the currentPage AEM global object), we can make use of the HierarchyNodeInheritanceValueMap.class, and currentPage resource to initialise the InheritanceValueMap.class object. Next, calling the method getInherited(String name, Class<T> type), we are able to get the inherited page property.

1
2
3
4
5
6
7
8
9
10
11
<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="com.day.cq.commons.inherit.InheritanceValueMap" %>
<%@ page import="com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap" %>

<%
    InheritanceValueMap ivm = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
    String inheritedValueMyCustomProperty = ivm.getInherited("myCustomerProperty", String.class);
    String inheritedValueJcrTitle = ivm.getInherited("jcr:title", String.class);
%>
inheritedValueMyCustomProperty = <%= inheritedValueMyCustomProperty %>
inheritedValueJcrTitle = <%= inheritedValueJcrTitle %>

3. inheritedPageProperties with OSGI Bundle, Java Backend

Similar to the JSP implementation above, we can make use of the HierarchyNodeInheritanceValueMap.class, and currentPage resource to initialise the InheritanceValueMap.class object. Next, calling the method getInherited(String name, Class<T> type), we are able to get the inherited page property.

1
2
3
4
5
6
7
8
9
import com.day.cq.commons.inherit.InheritanceValueMap;
import com.day.cq.commons.inherit.HierarchyNodeInheritanceValueMap;

@ScriptVariable
private Page currentPage;
...
InheritanceValueMap ivm = new HierarchyNodeInheritanceValueMap(currentPage.getContentResource());
String inheritedValueMyCustomProperty = ivm.getInherited("myCustomerProperty", String.class);
String inheritedValueJcrTitle = ivm.getInherited("jcr:title", String.class);





Hello, I am an enthusiastic Adobe Community Advisor and a seasoned Lead AEM Developer. I am currently serving as an AEM Technical Lead at MNPDigital.ca, bringing over a decade of extensive web engineering experience and more than eight years of practical AEM experience to the table. My goal is to give back to the AEM Full Stack Development community by sharing my wealth of knowledge with others. You can connect with me on LinkedIn.

One thought on “AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle

Leave a Reply

Your email address will not be published. Required fields are marked *


Back To Top