Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Apply page policy through code


Level 6


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



2 Replies


Community Advisor

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.



// 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", "");
//saving changes

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now