Skip to content

Instantly share code, notes, and snippets.

@nateyolles
Created March 27, 2016 18:52
Show Gist options
  • Save nateyolles/f795100e8774cdbbf55c to your computer and use it in GitHub Desktop.
Save nateyolles/f795100e8774cdbbf55c to your computer and use it in GitHub Desktop.
AEM com.adobe.granite.confmgr.Conf example of using the com.adobe.granite.confmgr.ConfMgr service
package com.nateyolles.aem.slashconf.core.models;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;
import com.adobe.granite.confmgr.Conf;
import com.adobe.granite.confmgr.ConfMgr;
/**
* AEM com.adobe.granite.confmgr.Conf example of getting a configuration using
* the ConfMgr service rather than adapting a Resource.
*/
@Model(adaptables = SlingHttpServletRequest.class)
public class ConfServiceModel {
@Inject
private ConfMgr confMgr;
@Inject
private Resource currentResource;
@PostConstruct
protected void init() {
final Conf conf = confMgr.getConf(currentResource);
final ValueMap fooSettings = conf.getItem("socialmedia/foo");
final String name = fooSettings.get("name", String.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment