template refactor policies | Community
Skip to main content
June 20, 2025
Solved

template refactor policies

  • June 20, 2025
  • 2 replies
  • 549 views

we have two editable templates and both allowing two components which are mentioned below.

now instead of defining these component two policies in each template policies. how can i refactor to add at single place and refer and refactor the code?

<carousel
cq:policy="abc/components/content/carousel/policy_hero-carousel"
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/core/components/policies/mapping"/>
<mediahero
cq:policy="abc/components/content/mediahero/policy_episodepage_mediahero"
jcr:primaryType="nt:unstructured"
sling:resourceType="wcm/core/components/policies/mapping"/>

Best answer by VeenaVikraman

Hi @sudarshanv1

Your question is really valid. This is something I tried solving long back. The duplication of cq:policy entries across templates definitely feels unnecessary.

But from what I understand, the cq:policy is already pointing to a common path where the actual policy is defined. So even though you're repeating the same reference in multiple templates, you're not duplicating the policy itself, you're just telling Sling where to look. This seems to be how the Sling language is designed to work.

That said, I don’t think there’s a way to simplify it further. You still need to define the reference in each template. I also found no option to group or reuse the mappings in a cleaner way.

Thanks
Veena ✌️

2 replies

TarunKumar
Community Advisor
Community Advisor
June 20, 2025

HI @sudarshanv1 ,

All these components policy which is cq:policy reside under one node "/conf/your-project/settings/wcm/policies/".
And these are specific to components. Though your component is allowed under template which redirects to these policy.
Now in your case if you want to target one common policy you can redirect it from your template level .

 

 

-Tarun

June 20, 2025

true we can target from the template level but
my question is:
instead of defining in each template, i want to define at single place and refer it by each template.

arunpatidar
Community Advisor
Community Advisor
June 20, 2025

Hi @sudarshanv1 

No, this is not possible, each templates required a policy node with references.
You can't refer/inherit template policy from another node except policy itself.

Arun Patidar
VeenaVikraman
Community Advisor
VeenaVikramanCommunity AdvisorAccepted solution
Community Advisor
June 20, 2025

Hi @sudarshanv1

Your question is really valid. This is something I tried solving long back. The duplication of cq:policy entries across templates definitely feels unnecessary.

But from what I understand, the cq:policy is already pointing to a common path where the actual policy is defined. So even though you're repeating the same reference in multiple templates, you're not duplicating the policy itself, you're just telling Sling where to look. This seems to be how the Sling language is designed to work.

That said, I don’t think there’s a way to simplify it further. You still need to define the reference in each template. I also found no option to group or reuse the mappings in a cleaner way.

Thanks
Veena ✌️