How can I inherit page properties | Community
Skip to main content
February 15, 2023
Solved

How can I inherit page properties

  • February 15, 2023
  • 5 replies
  • 6341 views

I have created a template based on a base page template and I have added one new property to a new template.

Now I want to inherit the new property to all the pages

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 Preetpal_Bindra

Hello @kunald36548265 

As suggested by others in this thread, you can use the inheritedPageProperties.<your-property> in the sightly code to inherit <your-property> in child pages.

 

Use case where I've used inheritedPageProperties:

The requirement is to select a site section only on the top level page of a content tree and all pages underneath that page must use the same site section.

This requirement was achieved using inheritedPageProperties

A new property ( of type = select list) named "siteSection" is defined at the page template dialog. This select list has a predefined list of names of the various areas of the site. Along with that, the sightly code has the <meta name="" content=""> HTML HEAD attribute in on the page that looks for a property by the name "siteSection" on the current page.

If found on the current page, then it reads it and displays the value.

If not found, inheritedPageProperties climbs at its parent page and looks for a property by the name "siteSection". If found, reads it and displays it. If not, then repeats the process up in the page hierarchy until it finds a value to the property.

 

The marketing business team set the property only on handful of pages and the entire site had the attribute showing in no time.

 

<data-sly-test="${inheritedPageProperties.siteSection}"> <meta name="site_section" content="inheritedPageProperties.siteSection"> </sly>

 

 

regards,

Preetpal

5 replies

Sady_Rifat
Community Advisor
Community Advisor
February 15, 2023

For getting parent page properties from child page, you can use

 

<div> ${inheritedPageProperties.myProperties} </div>

 


Referencehttps://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-inheritedpageproperties-with-sightly-jsp-osgi-bundle-aem/m-p/379977

Jagadeesh_Prakash
Community Advisor
Community Advisor
February 15, 2023

@kunald36548265  You can conditionally also check for empty case for inherited page properties

 

<link rel="icon" type="image/png" href="${inheritedPageProperties.favIcon ? inheritedPageProperties.favIcon : '/content/dam/***/favicon.png'}"/>
Adobe Employee
February 15, 2023

In case you are talking about metadata properties of parent dialogue, you should use Sling Resource Merger. Explore this link - https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/sling-resource-merger.html?lang=en

 

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 15, 2023

You need ton to understand that when viewing the component in the XF environment /content/experience-fragments/* or /conf, inheritedProperties will never be visible. Until you visit the page that utilizes the XF... which content is rendered under /content/my-site/*, then you will be able to see the inheritedPageProperties being rendered.

 

Here's how you would do it in sightly, JSP, and backend Sling Models:

 

Sightly:

${inheritedPageProperties.myCustomProperty} ${inheritedPageProperties['myCustomProperty']} ${inheritedPageProperties.jcr:title} ${inheritedPageProperties['jcr:title']}

 

JSP:

<%@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 %>



Sling Models:

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);

 

Learn more from the documentation here: AEM inheritedpageproperties with Sightly, JSP, OSGI Bundle - Sourced Code

Preetpal_Bindra
Community Advisor
Preetpal_BindraCommunity AdvisorAccepted solution
Community Advisor
February 16, 2023

Hello @kunald36548265 

As suggested by others in this thread, you can use the inheritedPageProperties.<your-property> in the sightly code to inherit <your-property> in child pages.

 

Use case where I've used inheritedPageProperties:

The requirement is to select a site section only on the top level page of a content tree and all pages underneath that page must use the same site section.

This requirement was achieved using inheritedPageProperties

A new property ( of type = select list) named "siteSection" is defined at the page template dialog. This select list has a predefined list of names of the various areas of the site. Along with that, the sightly code has the <meta name="" content=""> HTML HEAD attribute in on the page that looks for a property by the name "siteSection" on the current page.

If found on the current page, then it reads it and displays the value.

If not found, inheritedPageProperties climbs at its parent page and looks for a property by the name "siteSection". If found, reads it and displays it. If not, then repeats the process up in the page hierarchy until it finds a value to the property.

 

The marketing business team set the property only on handful of pages and the entire site had the attribute showing in no time.

 

<data-sly-test="${inheritedPageProperties.siteSection}"> <meta name="site_section" content="inheritedPageProperties.siteSection"> </sly>

 

 

regards,

Preetpal