Tips of using Sightly in AEM6

Here are some tips of using Sightly in AEM6

Passing arguments

  • To avoid comlex expressions inside emplates, Sightly does not allow passing arguments to functional call. Only zero argument calls are allowed from templates
  • Java Use-API doesn’t support passing parameters to the getter method You may pass parameters once, during the Use class initialization. Take a look on this example inspired by the Sightly documentation

<!– info.html –>
< div data-sly-use.info=”${‘Info’ @ text=’Some text’}” >
< p>${info.reversed}< /p>
< /div>

// Info.java
public class Info extends WCMUse {

private String reversed;

@Override
public void activate() throws Exception {
String text = get(“text”, String.class);
reversed = new StringBuilder(text).reverse().toString();
}

public String getReversed() {
return reversed;
}
}

Make page to be authorable

Put < div data-sly-include=”/libs/wcm/core/components/init/init.jsp”>< /div> in header

Loading Client Libraries

The client libraries helper template library (/libs/granite/sightly/templates/clientlib.html) can be loaded through data-sly-use and stored in a clientLib block element variable. Loading the library’s CSS style sheets and JavaScript is done through data-sly-call. The clientLib template library exposes three templates:

  • css – loads only the CSS files of the referenced client libraries
  • js – loads only the JavaScript files of the referenced client libraries
  • all – loads all the files of the referenced client libraries

Each helper template defines a categories option that accepts either an array of string values or a string containing a comma separated values list for referencing the desired client libraries. Example:

Referencing client libraries components in different sections of a page
< head data-sly-use.clientLib=”${‘/libs/granite/sightly/templates/clientlib.html’}” >
<  css data-sly-call=”${clientLib.css @ categories=[‘category1’, ‘category2’]}” data-sly-unwrap/ >
< /head>
< body>
< !– content — >
< js data-sly-call=”${clientLib.js @ categories=[‘category1’, ‘category2’]}” data-sly-unwrap/ >
< /body>

Referencing client libraries in the <head> tag of a page
< head data-sly-use.clientLib=”${‘/libs/granite/sightly/templates/clientlib.html’}”>
< clientlib data-sly-call=”${clientLib.all @ categories=[‘category1’, ‘category2’]}” data-sly-unwrap / >
< /head>

Pass params between htmls via data-sly-template and  data-sly-call

renderer.html: this page has html template blocks
< div data-sly-use.lib=”renderer.html” data-sly-unwrap data-sly-call=”${lib.simpleTextRenderer @ foods=[‘Coffee’,’Tea’,’Milk’,’Rice’,’Other’]}”>< /div>

sightly-cmponent.html
< div data-sly-template.simpleTextRenderer=”${@ foods}”>
< ul data-sly-list.food=”${foods}” class=”simple-list”>
< li>${food}< /li>
< /ul>
< /div>

5. Great resrouces

Tips of using Sling model in AEM6

Here are some tips of using Sling model in AEM6

1. Config pom in my app bundle

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Sling-Model-Packages>
au.com.sensis.yp.selcitra.slingmodels
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>

2. Config debug log
Go to http://localhost:4502/system/console/configMgr, add org.apache.sling.commons.log.LogManager item with org.apache.sling.models
slingmodel-log

3. AEM6 uses slign model 1.0.0, so some features are not avaliable:
1) Collecton/List injection are introduced from 1.0.6, I use code below
2) Can’t inject field like @named(“jcr:name”) etc, So I use AEM Objects Sling Models Injector to achieve this

@Inject
private Resource resource;

public String getName() {
resouce.getName();
}

4. Which injectors are available
http://localhost:4502/system/console/status-slingmodels

5. Great resrouces
https://sling.apache.org/documentation/bundles/models.html
https://docs.adobe.com/docs/en/aem/6-0/develop/platform/sling-adapters.html
http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html

6. Node types resources
https://docs.adobe.com/docs/en/aem/6-0/develop/platform/custom-nodetypes.html
http://jackrabbit.apache.org/jcr/node-type-visualization.html
https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/commons/jcr/JcrConstants.html

What are the sling changes within AEM 6.1

The list below are quoted from  a great blog https://cqdump.wordpress.com/2015/06/05/what-is-new-in-sling-with-aem-6-1.

SYMBOLIC NAME OF THE BUNDLE

AEM 5.6.1

AEM 6.0

AEM 6.1

org.apache.sling.adapter

2.1.0

2.1.0

2.1.4

org.apache.sling.api

2.4.3.R1488084

2.7.0

2.9.0

org.apache.sling.atom.taglib

0.9.0.R988585

0.9.0.R988585

0.9.0.R988585

org.apache.sling.auth.core

1.1.2

1.1.7.R1584705

1.3.6

org.apache.sling.bgservlets

0.0.1.Rev1231138

0.0.1.R1582230

0.0.1.R1582230

org.apache.sling.bundleresource.impl

2.1.2

2.2.0

2.2.0

org.apache.sling.commons.classloader

1.3.0

1.3.2

1.3.2

org.apache.sling.commons.compiler

2.1.0

2.1.0

2.2.0

org.apache.sling.commons.fsclassloader

1.0.0

org.apache.sling.commons.html

1.0.0

1.0.0

1.0.0

org.apache.sling.commons.json

2.0.6

2.0.6

2.0.10

org.apache.sling.commons.log

3.0.0

4.0.0

4.0.2

org.apache.sling.commons.logservice

1.0.2

1.0.2

1.0.4

org.apache.sling.commons.mime

2.1.4

2.1.4

2.1.8

org.apache.sling.commons.osgi

2.2.0

2.2.0

2.2.2

org.apache.sling.commons.scheduler

2.3.4

2.4.2

2.4.6

org.apache.sling.commons.threads

3.1.0

3.2.0

3.2.0

org.apache.sling.datasource

1.0.0

org.apache.sling.discovery.api

0.1.0.R1484784

1.0.0

1.0.2

org.apache.sling.discovery.impl

0.1.0.R1486590

1.0.8

1.1.0

org.apache.sling.discovery.support

0.1.0.R1484784

1.0.0

1.0.0

org.apache.sling.distribution.api

0.1.0

org.apache.sling.distribution.core

0.1.1.r1678168

org.apache.sling.engine

2.2.8

2.3.3.R1588174

2.4.2

org.apache.sling.event

3.1.5.R1485539

3.3.10

3.5.5.R1667281

org.apache.sling.event.dea

1.0.0

org.apache.sling.extensions.threaddump

0.2.2

0.2.2

0.2.2

org.apache.sling.extensions.webconsolesecurityprovider

1.0.0

1.0.0

1.1.4

org.apache.sling.featureflags

1.0.0

1.0.0

org.apache.sling.fragment.ws

1.0.2

1.0.2

1.0.2

org.apache.sling.fragment.xml

1.0.2

1.0.2

1.0.2

org.apache.sling.hc.core

1.1.0

1.2.0

org.apache.sling.hc.webconsole

1.1.0

1.1.2

org.apache.sling.i18n

2.2.4

2.2.8

2.4.0

org.apache.sling.installer.api

1.0.0

org.apache.sling.installer.console

1.0.0

1.0.0

1.0.0

org.apache.sling.installer.core

3.4.6

3.5.0

3.6.4

org.apache.sling.installer.factory.configuration

1.0.10

1.0.12

1.1.2

org.apache.sling.installer.factory.subsystems

1.0.0

org.apache.sling.installer.provider.file

1.0.2

1.0.2

1.1.0

org.apache.sling.installer.provider.jcr

3.1.6

3.1.6

3.1.16

org.apache.sling.javax.activation

0.1.0

0.1.0

0.1.0

org.apache.sling.jcr.api

2.1.0

2.2.0

2.2.0

org.apache.sling.jcr.base

2.1.2

2.2.2

2.2.2

org.apache.sling.jcr.classloader

3.1.12

3.2.0

org.apache.sling.jcr.compiler

2.1.0

2.1.0

2.1.0

org.apache.sling.jcr.contentloader

2.1.6

2.1.6

2.1.10

org.apache.sling.jcr.davex

1.2.0

1.2.0

1.2.2

org.apache.sling.jcr.jcr-wrapper

2.0.0

2.0.0

2.0.0

org.apache.sling.jcr.registration

0.0.1.R1345943

1.0.0

1.0.2

org.apache.sling.jcr.resource

2.2.9.R1483758

2.3.7.R1591843

2.5.0

org.apache.sling.jcr.resourcesecurity

0.0.1.R1562502

1.0.2

org.apache.sling.jcr.webdav

2.2.0

2.2.2

2.2.2

org.apache.sling.jmx.provider

1.0.2

1.0.2

org.apache.sling.launchpad.installer

1.2.0

1.2.0

1.2.0

org.apache.sling.models.api

1.0.0

1.1.0

org.apache.sling.models.impl

1.0.2

1.1.0

org.apache.sling.resource.inventory

1.0.2

1.0.4

org.apache.sling.resourceaccesssecurity

0.0.1.R1579485

1.0.0

org.apache.sling.resourcecollection

0.0.1.R1479861

1.0.0

1.0.0

org.apache.sling.resourcemerger

1.1.2

1.2.9.R1675563-B002

org.apache.sling.resourceresolver

1.0.6

1.1.0

1.2.4

org.apache.sling.rewriter

1.0.4

1.0.4

1.0.4

org.apache.sling.scripting.api

2.1.4

2.1.6

2.1.6

org.apache.sling.scripting.core

2.0.24

2.0.26

2.0.28

org.apache.sling.scripting.java

2.0.6

2.0.6

2.0.12

org.apache.sling.scripting.javascript

2.0.12

2.0.13.R1566989

2.0.16

org.apache.sling.scripting.jsp

2.0.28

2.0.28

2.1.6

org.apache.sling.scripting.jsp.taglib

2.1.8

2.2.0

2.2.4

org.apache.sling.scripting.jst

2.0.6

2.0.6

2.0.6

org.apache.sling.scripting.sightly

1.0.2

org.apache.sling.scripting.sightly.js.provider

1.0.4

org.apache.sling.security

1.0.4

1.0.6

1.0.10

org.apache.sling.serviceusermapper

1.0.0

1.2.0

org.apache.sling.servlets.compat

1.0.0.Revision1200172

1.0.0.Revision1200172

1.0.0.Revision1200172

org.apache.sling.servlets.get

2.1.4

2.1.8

2.1.10

org.apache.sling.servlets.post

2.3.1.R1485589

2.3.4

2.3.6

org.apache.sling.servlets.resolver

2.2.4

2.3.2

2.3.6

org.apache.sling.settings

1.2.2

1.3.0

1.3.6

org.apache.sling.startupfilter

0.0.1.Rev1387008

0.0.1.Rev1526908

0.0.1.Rev1526908

org.apache.sling.startupfilter.disabler

0.0.1.Rev1387008

0.0.1.Rev1387008

0.0.1.Rev1387008

org.apache.sling.tenant

1.0.0

1.0.0

1.0.2