Hi,
I have a requirement to apply web resource clientlib in page policy through backend code, the template editors can choose but I want it through backend code
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Vani1012,
On code level you can use following api to get policy definition and do some changes:
Below is a sample code snippet. It gets template definition, to retrieve information about specific policy that is used by Page Policy, and set value of appResourcesClientlib property that represents Web Resources Client Library on GUI level.
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
import com.day.cq.wcm.api.policies.ContentPolicy;
import com.day.cq.wcm.api.policies.ContentPolicyMapping;
// path to template definition
String templatePath = "/conf/we-retail/settings/wcm/templates/content-page";
Resource templateResource = resourceResolver.getResource(templatePath + "/policies/jcr:content");
// getting policy from given template resource
ContentPolicy contentPolicy = templateResource.adaptTo(ContentPolicyMapping.class).getPolicy();
// getting value map to set some properties
ModifiableValueMap modifiableValueMap = contentPolicy.adaptTo(Resource.class).adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("appResourcesClientlib", "dam.gui.msm.properties");
//saving changes
resourceResolver.commit();
Hi @Vani1012,
On code level you can use following api to get policy definition and do some changes:
Below is a sample code snippet. It gets template definition, to retrieve information about specific policy that is used by Page Policy, and set value of appResourcesClientlib property that represents Web Resources Client Library on GUI level.
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
import com.day.cq.wcm.api.policies.ContentPolicy;
import com.day.cq.wcm.api.policies.ContentPolicyMapping;
// path to template definition
String templatePath = "/conf/we-retail/settings/wcm/templates/content-page";
Resource templateResource = resourceResolver.getResource(templatePath + "/policies/jcr:content");
// getting policy from given template resource
ContentPolicy contentPolicy = templateResource.adaptTo(ContentPolicyMapping.class).getPolicy();
// getting value map to set some properties
ModifiableValueMap modifiableValueMap = contentPolicy.adaptTo(Resource.class).adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("appResourcesClientlib", "dam.gui.msm.properties");
//saving changes
resourceResolver.commit();
Please check sample policy xml file which are deployed vai code
Views
Likes
Replies
Views
Likes
Replies