In this article, we will go through the 3 different ways in how we can retrieve inherited page properties.
1. inheritedPageProperties with Sightly
Sightly offers a plethora of AEM Global objects, and one of them notably is the “inheritedPageProperties”. Utilizing the inheritedPageProperties global object, we can use dot or square bracket notation to access the inherited page property value.
${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.
<%@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 the currentPage resource to initialize the InheritanceValueMap.class object. Next, calling the method get inherited(String name, Class<T> type), we are able to get the inherited page property.
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);
No comments:
Post a Comment
If you have any doubts or questions, please let us know.