Customizing Cloud Service configuration in AEM
There are many cloud services provided out of the box to connect aem with the adobe marketing cloud & third party services.
You can access cloud services by Cloud Services
8:- Go to http://localhost:4502/miscadmin#/etc/cloudservices and create a new page:
10:- Provide required values in the respective Fields and click OK.Your new configuration is ready to use on page.
11:-You can also check your newly created cloud service inside http://localhost:4502/etc/cloudservices.html under Third Party Services.
12:-Navigate to a page and add the newly created configuration in the page properties, under the Cloud Services tab.
How to use cloud service configuration values:-
You can use code below to retrive configuration values and can use accordingly.
final String[] services = getInheritedPageProperties().get("cq:cloudserviceconfigs", String[].class);
final ConfigurationManager cfgMgr = getResourceResolver().adaptTo(ConfigurationManager.class);
if (cfgMgr != null) {
final Configuration testCloudConfig = cfgMgr.getConfiguration("testcloudservice", services);
if (testCloudConfig != null) {
final String field1 = testCloudConfig.get("field1", StringUtils.EMPTY);
final String field2 = testCloudConfig.get("field2", StringUtils.EMPTY);
final String field3 = testCloudConfig.get("field3", StringUtils.EMPTY);
}
}
Hope this helps!
You can access cloud services by Cloud Services
Some of the mostly used cloud service configurations are:-
- DTM
- Adobe Target
- Adobe Analytics
- Adobe Campaign
- Livefyre
- Facebook Connect
- Twitter Connect
- Youtube
- reCaptcha
Most useful and strong feature of Cloud Service is that it allows inheritance from parent pages to child pages with the ability to break the inheritance at any level.So You can provide configuration at site top level/root page and all the child pages can use the same configuration by default.
If you want to change the configuration at any level you can create a separate configuration for that page or simple uncheck the inheritance at child lev
You can configure cloud service like this and can use at page level.
1:-Click on Configure now to create a new configuration.Give Name and title and click on create.
3: Open page properties of site root page or page where you want to use these properties and go to Cloud Services Tab.
Creating Custom Cloud Service:-
We can also create a custom cloud service for our project use case where we want to connect our website with some third party product which is not the part of listed third party cloud services in http://localhost:4502/libs/cq/core/content/tools/cloudservices.html
Steps to create a new cloud Service:-
To create a new custom cloud service follow below steps.
1:- Go to http://localhost:4502/crx/de/index.jsp
1:- Go to http://localhost:4502/crx/de/index.jsp
2:- In your project hierarchy Select Create --> Create Component...
3:-Provide following in the Create component dialog.
3:-Provide following in the Create component dialog.
- Label: testcloudpage
- Title: Test Cloud Service Page
- Super Type: cq/cloudserviceconfigs/components/configpage
- Group: .hidden
4:-Suppose our test cloud service will have three field named field1,field2 & field3 as configurable.
So create a new file content.jsp under component created.
add following content.
6:-Now copy /libs/cq/cloudserviceconfigs/components/configpage/body.jsp to your created component parallel to content.jsp & remove testcloudpage.jsp.
7:- Create a new template under /apps/test-project/templates which will use this page component just created for cloud service.
- Resource Type = path of your created component:test-project/components/pages/testcloudpage
- Label = testcloudservice
- Title = Test Cloud Service Template
- allowedPath = /etc/cloudservices/testcloudservice(/.*)?
- allowedChildren = /apps/yourproject/templates/testcloudservice
- sling:resourceSuperType = cq/cloudserviceconfigs/templates/configpage (on template node, not the jcr:content node)
8:- Go to http://localhost:4502/miscadmin#/etc/cloudservices and create a new page:
- Title: Test Cloud Service
- Name: testcloudservice
- Parent Configuration: /etc/cloudservices/testcloudservice
- Title: Test Cloud Service Configuration
- Name:TestCloudServiceConfiguration
click Create.
How to use cloud service configuration values:-
You can use code below to retrive configuration values and can use accordingly.
final String[] services = getInheritedPageProperties().get("cq:cloudserviceconfigs", String[].class);
final ConfigurationManager cfgMgr = getResourceResolver().adaptTo(ConfigurationManager.class);
if (cfgMgr != null) {
final Configuration testCloudConfig = cfgMgr.getConfiguration("testcloudservice", services);
if (testCloudConfig != null) {
final String field1 = testCloudConfig.get("field1", StringUtils.EMPTY);
final String field2 = testCloudConfig.get("field2", StringUtils.EMPTY);
final String field3 = testCloudConfig.get("field3", StringUtils.EMPTY);
}
}
Hope this helps!
Hi,
ReplyDeleteHow can I handle the event on the "Ok" button from the pop-up in which you introduce the configuration? I need to add some extra logic besides the saving process that is behind that button.