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"/>
Solved! Go to Solution.
Views
Replies
Total Likes
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
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
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.
Views
Replies
Total Likes
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.
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
Views
Likes
Replies