Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
yupadhyay / CustomConfigFactory.java
Created February 14, 2016 18:13
Create Custom ConfigFactory AEM
Here is how you can use configuration factory,
public interface MyCustomService{
}
--------------------------------------------
@yupadhyay
yupadhyay / ConfigFacotry.java
Created February 14, 2016 18:10
ConfigFactory in AEM
package wemblog.configfactory.test
@Component(configurationFactory = true, metatype = true)
@Service(value = MyCustomService.class)
public Class WemBlogFactory implements WemBlogService{
@Property(label="Test Property",name="test", description="This is test property example", value="test")
private String test;
#Initialize a variable
<sly data-sly-test.pagePath="${currentPage.path}"/>
<sly data-sly-test.someString='test'/>
<sly data-sly-use.SomeOtherObject="${'TopNavHelperUse' @ test='test'}">
<sly class="sightly-topnav" data-sly-use.topnav="${'Topnav' @ pageNumber='5', someString=someString, pageObject=currentPage, helperString=SomeOtherObject.test}"/>
${topnav.totalPage} ${topnav.someOtherString} ${topnav.pagePath} ${topnav.helperTest}
#Here is Output
package wemblog.sightly.use
@Model(adaptables = SlingHttpServletRequest.class)
public class ExternalUrl {
@Inject
private Externalizer externalizer;
@Inject // Using the bindings from Sightly (${currentPage.path}
protected Page currentPage;
@Inject @Optional // parameter from data-sly-use
@yupadhyay
yupadhyay / HashMapSightly.java
Created February 7, 2016 20:13
Accessing Hashmap in Sightly
package com.test;
import java.util.HashMap;
import java.util.Map;
import com.adobe.cq.sightly.WCMUse;
public class WcmUseSample extends WCMUse {
private Map<String, String> myHashMap;
public void activate() throws Exception {
@yupadhyay
yupadhyay / StringArraySightly.java
Created February 7, 2016 20:02
Access String Array in Sightly
ackage com.project.sightly;
import com.adobe.cq.sightly.WCMUse;
import org.apache.sling.commons.json.JSONObject;
import java.util.*;
public class JsonHelper extends WCMUse {
private String[] json;
#In your Java Class
#this assumes that there is a multi string property tabs
package com.wemblog.use;
public class WemBlogUse extends WCMUse {
/**
* CASE 1: Just access a multi value property and iterate over them
*/
public Iterator<Map<String, Object>> getTabTitles(){
List<Map<String, Object>> infos = new LinkedList<Map<String,Object>>();
@yupadhyay
yupadhyay / FixedSetSightly.html
Created February 7, 2016 19:23
Iterate through fixed set of list Sightly
#Fixed Array
<ul data-sly-list="${ [1,2,3,4] }">
<li>${item}</li>
</ul>
#List page children
<ul data-sly-list.child="${currentPage.listChildren}">
<li>${child.title}</li>
</ul>
@yupadhyay
yupadhyay / SightlyClientLibInclude.html
Created February 7, 2016 19:18
Include Clientlibs in Sightly
<head data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}">
<!--/* for css+js */-->
<meta data-sly-call="${clientLib.all @ categories='your.clientlib'}" data-sly-unwrap></meta>
<!--/* only js */-->
<meta data-sly-call="${clientLib.js @ categories='your.clientlib'}" data-sly-unwrap></meta>
<!--/* only css */-->
<meta data-sly-call="${clientLib.css @ categories='your.clientlib'}" data-sly-unwrap></meta>
@yupadhyay
yupadhyay / ReplicationUtilService.java
Created January 29, 2016 19:25
ReplicationUtilService.java
package com.wemblog.utility;
import java.util.List;
import org.apache.sling.api.resource.ResourceResolver;
import com.day.cq.replication.Agent;
import com.day.cq.replication.ReplicationActionType;
/**
* Replication Utility Method for some common replication task