2

I have a dynamic editable template with design dialog at page component. The design properties are persisted under /conf/myapp/settings/wcm/policies/myapp like this:

enter image description here

My requirement is to read these page level design properties and use them inside an Image component. I have design dialog at component level as well. So when I do ${currentStyle.property}, it renders the component level design property.

Next I wrote a helper class like this:

      Designer designer = currentPage.getContentResource().getResourceResolver().adaptTo(Designer.class);
      Design pageDesign = designer.getDesign(currentPage);
      Style pageStyle = pageDesign.getStyle(pageDesign.getPath());
      return pageStyle.get(PROPERTY_ANALYTICSPAGETYPE, String.class);

This code is trying to read page level design properties under /etc/designs/myapp authored under cq:designPath and NOT reading under /conf policies. Now how I read the /conf policy nodes and access those properties?

How to access page level design properties within a component?

Jamie Counsell
  • 7,730
  • 6
  • 46
  • 81
Saravana Prakash
  • 1,321
  • 13
  • 25

1 Answers1

2

This should give you the desired result :

ResourceResolver resourceResolver = this.request.getResourceResolver();
  ContentPolicyManager policyManager = (ContentPolicyManager)resourceResolver.adaptTo(ContentPolicyManager.class);
  if (policyManager != null)
  {
    ContentPolicy contentPolicy = policyManager.getPolicy(this.resource);
    if (contentPolicy != null) {
      this.myProperty = ((Boolean)contentPolicy.getProperties().get("myProperty", Boolean.valueOf(false))).booleanValue();
    }
Pakira
  • 1,951
  • 3
  • 25
  • 54
  • Thanks for sharing. This worked except instead of getPolicy(this.resource), I had todo getPolicy(currentPage.getContentResource) since I wanted Page Level design policy. – Saravana Prakash May 03 '18 at 20:10