Expand my Community achievements bar.

SOLVED

template refactor policies

Avatar

Level 3

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"/>

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

4 Replies

Avatar

Community Advisor

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

Avatar

Level 3

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.

Avatar

Community Advisor

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

AEM LinksLinkedIn

Avatar

Correct answer by
Community Advisor

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