SlideShare a Scribd company logo
Adobe Experience Manager
@GabrielWalt, Product Manager
Deep Dive into Sightly,

an open source templating language
Adobe Experience Manager
Specification and TCK open sourced to GitHub.

Reference implementation donated to Apache Sling.
Follow @sightlyio on Twitter.

http://docs.adobe.com/docs/en/aem/6-2/develop/sightly.html
Adobe Experience Manager
§ 1 Expression contexts
§ 2 Passing data to client libs
§ 3 Use statement
§ 4 Template & Call statements
§ 5 Parameters for sub-resources
Adobe Experience Manager
The context option offers control over escaping and XSS protection.
Allowing some HTML markup (filtering out scripts)

<div>${properties.jcr:description @ context='html'}</div>
Adding URI validation protection to other attributes than src or href

<p data-link="${link @ context='uri'}">text</p>
Display Context Option
Adobe Experience Manager
Most useful contexts and what they do:
number XSSAPI.getValidNumber
uri XSSAPI.getValidHref (default for src and href attributes)
attribute XSSAPI.encodeForHTMLAttribute (default for other attributes)
text XSSAPI.encodeForHTML (default for element content)
scriptString XSSAPI.encodeForJSString
styleString XSSAPI.encodeForCSSString
html XSSAPI.filterHTML
unsafe disables all protection, use at your own risk.
Display Context Option
<a href="${myLink}" title="${myTitle}">${myContent}</a>

<script> var foo = "${myVar @ context='scriptString'}"; </string>

<style> a { font-family: "${myFont @ context='styleString'}"; } </style>
safer
Adobe Experience Manager
Preferred method for each context:
– src and href attributes: number, uri, attribute, unsafe
– other attributes: number, uri, attribute, unsafe
– element content: number, text, html, unsafe
– JS scripts
⊛
: number, uri, scriptString, unsafe
– CSS styles
⊛
: number, uri, styleString, unsafe

⊛ An explicit context is required for script and style contexts.

Don’t set the context manually unless you understand what you are doing.
Display Context Option
<a href="${myLink}" title="${myTitle}">${myContent}</a>

<script> var foo = "${myVar @ context='scriptString'}"; </string>

<style> a { font-family: "${myFont @ context='styleString'}"; } </style>
Adobe Experience Manager
§ 1 Expression contexts
§ 2 Passing data to client libs
§ 3 Use statement
§ 4 Template & Call statements
§ 5 Parameters for sub-resources
Adobe Experience Manager
<!-- template.html -->

<div data-sly-use.logic="logic.js"

data-json="${logic.json}"></div>
/* logic.js */

use(function () {

return {

json: JSON.stringify({

foo: "bar",

arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

})

};

});
Passing data to client libs
Adobe Experience Manager
<!-- template.html -->

<script id="my-handlebar-template"

type="text/x-handlebars-template"

data-sly-include="handlebar.html"></script>
<!-- handlebar.html -->

<p>${properties.jcr:title}</p>
Server-side JavaScript logic
Adobe Experience Manager
http://bit.ly/sightly-data-json
http://bit.ly/sightly-script-angular
Passing data to client libraries
Adobe Experience Manager
§ 1 Expression contexts
§ 2 Passing data to client libs
§ 3 Use statement
§ 4 Template & Call statements
§ 5 Parameters for sub-resources
Adobe Experience Manager
Initializes a helper object.

<div data-sly-use.logic="logic.js">${logic.hi}</div>
Output:

<div>Hello World</div>








Use Statement
Adobe Experience Manager
<!-- template.html -->

<div data-sly-use.logic="logic.js">${logic.hi}</div>
/* logic.js */

use(function () {

return {

hi: "Hello World"

};

});
Like for the Sightly template, the objects available in the logic file are
the same ones as in JSP with global.jsp
Server-side JavaScript logic
Adobe Experience Manager
<!-- template.html -->

<div data-sly-use.logic="Logic">${logic.hi}</div>
/* Logic.java in component */

package apps.my_site.components.my_component;

import org.sling…sightly.WCMUsePojo;
public class Logic extends WCMUsePojo {

private String hi;
@Override

public void activate() throws Exception {

hi = "Hello World";

}
public String getHi() {

return hi;

}

}
Javalogic
When the Java files are
located in the content
repository, next to the
Sightly template, only
the class name is
needed.
POJOextendingWCMUse
Adobe Experience Manager
<!-- template.html -->

<div data-sly-use.logic="com.foo.Logic">${logic.hi}</div>
/* Logic.java in OSGi bundle */

package com.foo;

import javax.annotation.PostConstruct;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.annotations.Model;
@Model(adaptables = Resource.class)

public class Logic {

private String hi;
@PostConstruct

protected void init() {

hi = "Hello World";

}
public String getHi() {

return hi;

}

}
Javalogic
AdaptablewithSlingModels When embedded in 

an OSGi bundle, the
fully qualified Java class
name is needed.
The Use-API accepts classes that are
adaptable from Resource or Request.
Adobe Experience Manager
Model logic

This logic is not tied to a template and is potentially reusable among components.

It should aim to form a stable API that changes little, even in case of a full redesign.
➔ Java located in OSGi bundle
View logic

This logic is specific to the templates and is likely to change if the design changes.

It is thus a good practice to locate it in the content repository, next to the template.
➔ JavaScript located in component 

If components are to be maintained by front-end devs (typically with Brackets).
➔ Java located in component

If performance is critical (e.g. when many requests are not cached by the dispatcher).
What kind of Use-API?
Adobe Experience Manager
Start simple: first, no code!
OSGi (Model)
Resource
API
Page
API
Content Repository
Component (View)Content Structure
sling:
resourceType
Resource Template
– Sling plays the role of the controller
and resolves the sling:resourceType,
deciding which component will
render the accessed resource.
– The component plays the role of the
view and it’s Sightly template builds
the corresponding markup.
– The Resource and Page APIs play the
role of the model, which are available
from the template as variables.
Adobe Experience Manager
Add logic only where needed
– Model Logic is
needed only if the
logic to access the
data is different to
what existing APIs
provide.
– View Logic is
needed only when
the template needs
additional data
preparation.
OSGi (Model)
Resource
API
Page
API
Model Logic
Content Repository
Component (View)Content Structure
sling:
resourceType data-sly-use
Resource Template View Logic
Adobe Experience Manager
The logic can access the same variables than exist in the template.
JavaScript:

var title = properties.get("title");
Java extending WCMUse:

String title = getProperties().get("title", String.class);
Java with SlingModels:

@Inject @Optional

private String title;
Use-API Bindings
Adobe Experience Manager
With the same notation as for template parameters, named
parameters can be passed to the Use-API.

<a data-sly-use.ext="${'Externalize' @ path='page.html'}"

href="${ext.absolutePath}">link</a>
Output:

<a href="/absolute/path/to/page.html">link</a>
Don’t pass variables that are part of the global binding (like properties
or resource) as they can be accessed from the logic too.
Use-API Parameters
Adobe Experience Manager
These parameters can then be read in from the various Use-API.
JavaScript:

var path = this.path;
Java extending WCMUse:

String path = get("path", String.class);
Java with SlingModels (works only when adapting from Request):

@Inject @Optional

private String path;
Use-API Parameters
Adobe Experience Manager
The use statement can also load data-sly-template markup
snippets located in other files.

<!-- library.html -->

<template data-sly-template.foo="${@ text}">

<span class="example">${text}</span>

</template>
<!-- template.html -->

<div data-sly-use.library="library.html"

data-sly-call="${library.foo @ text='Hi'}"></div>
Output:

<div><span class="example">Hi</span></div>
Use with Template & Call
Adobe Experience Manager
§ 1 Expression contexts
§ 2 Passing data to client libs
§ 3 Use statement
§ 4 Template & Call statements
§ 5 Parameters for sub-resources
Adobe Experience Manager
Declare and call a markup snippet with named parameters.

<template data-sly-template.foo="${@ class, text}">

<span class="${class}">${text}</span>

</template>
<div data-sly-call="${foo @ class='example',

text='Hi'}"></div>
Output:

<div><span class="example">Hi</span></div>
Template & Call Statements
Defining template parametersDeclaring template name
Template content
Calling template by name
Passing named parameters
Adobe Experience Manager
Advanced example of a recursive site map with template, call and list.

<ol data-sly-template.listChildren="${@ page}"

data-sly-list="${page.listChildren}">

<li>

<div class="title">${item.title}</div>

<ol data-sly-call="${listChildren @ page=item}"></ol>

</li>

</ol>
<ol data-sly-call="${listChildren @ page=currentPage}"></ol>
Template & Call Statements
Adobe Experience Manager
§ 1 Expression contexts
§ 2 Passing data to client libs
§ 3 Use statement
§ 4 Template & Call statements
§ 5 Parameters for sub-resources
Adobe Experience Manager
http://bit.ly/sightly-attributes
http://bit.ly/sightly-synthetic
Parameters for sub-resources
Adobe Experience Manager
Thank you!
• Documentation

https://docs.adobe.com/docs/en/aem/6-2/develop/sightly.html
• Specification

https://github.com/Adobe-Marketing-Cloud/sightly-spec
• REPL (Read-Eval-Print Loop) live Sightly execution environment

https://github.com/Adobe-Marketing-Cloud/aem-sightly-repl

@GabrielWalt, Product Manager
AEM Sightly Deep Dive

More Related Content

PPTX
Sightly - Part 2
PDF
Understanding Sling Models in AEM
PPTX
HTL(Sightly) - All you need to know
PDF
AEM Sightly Template Language
PDF
Aem dispatcher – tips & tricks
PDF
HTML5: features with examples
PPTX
PDF
AEM Best Practices for Component Development
Sightly - Part 2
Understanding Sling Models in AEM
HTL(Sightly) - All you need to know
AEM Sightly Template Language
Aem dispatcher – tips & tricks
HTML5: features with examples
AEM Best Practices for Component Development

What's hot (20)

PPTX
Rest and Sling Resolution
PPTX
Css pseudo-classes
PPTX
AEM Rich Text Editor (RTE) Deep Dive
PPTX
(Fast) Introduction to HTML & CSS
PPTX
Introduction to Sightly and Sling Models
PDF
Intro to HTML & CSS
PDF
CSS Day: CSS Grid Layout
PPT
PPTX
Angular Data Binding
PPTX
Experience and Content Fragment
PPTX
Java script
PPTX
Sling models by Justin Edelson
PPTX
AEM - Client Libraries
PPTX
Javascript best practices
PDF
JCR, Sling or AEM? Which API should I use and when?
PDF
Basics of JavaScript
PDF
Intro to HTML and CSS basics
PPTX
Javascript 101
PPT
Java Persistence API (JPA) Step By Step
Rest and Sling Resolution
Css pseudo-classes
AEM Rich Text Editor (RTE) Deep Dive
(Fast) Introduction to HTML & CSS
Introduction to Sightly and Sling Models
Intro to HTML & CSS
CSS Day: CSS Grid Layout
Angular Data Binding
Experience and Content Fragment
Java script
Sling models by Justin Edelson
AEM - Client Libraries
Javascript best practices
JCR, Sling or AEM? Which API should I use and when?
Basics of JavaScript
Intro to HTML and CSS basics
Javascript 101
Java Persistence API (JPA) Step By Step
Ad

Viewers also liked (20)

PDF
The six key steps to AEM architecture
PPTX
Sling Models Overview
PPTX
AEM (CQ) Dispatcher Caching Webinar 2013
PDF
Build single page applications using AngularJS on AEM
PPTX
AEM (CQ) Dispatcher Security and CDN+Browser Caching
PDF
Sling Models Using Sightly and JSP by Deepak Khetawat
PDF
EVOLVE'14 | Enhance | Gabriel Walt | Sightly Component Development
PDF
So how do I test my Sling application?
PDF
Three WEM Dev Tricks
PPTX
Web Apps atop a Content Repository
PPTX
EVOLVE'16 | Enhance | Oscar Bolaños & Justin Edelson | Search All the Things:...
PDF
Sling Component Filters in CQ5
PPTX
Continous Delivery with CQ
PPTX
Dynamic components using SPA concepts in AEM
PDF
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
PPTX
Aem best practices
PDF
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
PPTX
EVOLVE'16 | Deploy | Abhishek Dwevedi | Understanding a Typical AEM Deployment
PDF
User Interface customization for AEM 6
PDF
AEM 6.1 User Interface Customization
The six key steps to AEM architecture
Sling Models Overview
AEM (CQ) Dispatcher Caching Webinar 2013
Build single page applications using AngularJS on AEM
AEM (CQ) Dispatcher Security and CDN+Browser Caching
Sling Models Using Sightly and JSP by Deepak Khetawat
EVOLVE'14 | Enhance | Gabriel Walt | Sightly Component Development
So how do I test my Sling application?
Three WEM Dev Tricks
Web Apps atop a Content Repository
EVOLVE'16 | Enhance | Oscar Bolaños & Justin Edelson | Search All the Things:...
Sling Component Filters in CQ5
Continous Delivery with CQ
Dynamic components using SPA concepts in AEM
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Aem best practices
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
EVOLVE'16 | Deploy | Abhishek Dwevedi | Understanding a Typical AEM Deployment
User Interface customization for AEM 6
AEM 6.1 User Interface Customization
Ad

Similar to AEM Sightly Deep Dive (20)

PPTX
Sightly_techInsight
PDF
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
PDF
Ad111
PDF
Introduction to Sightly
PDF
Adobe Experience Manager Core Components
PDF
orcreatehappyusers
PDF
orcreatehappyusers
PDF
The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
PPT
BP204 - Take a REST and put your data to work with APIs!
PPTX
Introduction to JQuery, ASP.NET MVC and Silverlight
PDF
JS Single-Page Web App Essentials
PPTX
Design Like a Pro: How to Best Plan Your Perspective Project
PPTX
IMMERSE'16 Intro to Adobe Experience Manager & Adobe Marketing Cloud
PDF
Sightly - AEM6 UI Development using JS and JAVA
PPTX
Automated UI Testing
PPTX
ApacheCon North America - Introduction to FlexJS
PDF
Integrating with Adobe Marketing Cloud - Summit 2014
PDF
Ajax in AIR from On AIR Tour Europe
PPT
Develop a Quick and Dirty Web interface to your database: for the DBA and oth...
PPTX
Building Social Tools
Sightly_techInsight
AD111 -- Harnessing the Power of Server-Side JavaScript and Other Advanced XP...
Ad111
Introduction to Sightly
Adobe Experience Manager Core Components
orcreatehappyusers
orcreatehappyusers
The Ultimate Guide to Ad0 e103 adobe experience manager sites developer
BP204 - Take a REST and put your data to work with APIs!
Introduction to JQuery, ASP.NET MVC and Silverlight
JS Single-Page Web App Essentials
Design Like a Pro: How to Best Plan Your Perspective Project
IMMERSE'16 Intro to Adobe Experience Manager & Adobe Marketing Cloud
Sightly - AEM6 UI Development using JS and JAVA
Automated UI Testing
ApacheCon North America - Introduction to FlexJS
Integrating with Adobe Marketing Cloud - Summit 2014
Ajax in AIR from On AIR Tour Europe
Develop a Quick and Dirty Web interface to your database: for the DBA and oth...
Building Social Tools

More from Gabriel Walt (9)

PDF
Managing Omnichannel Experiences with Adobe Experience Manager (AEM)
PDF
Modernizing Adobe Experience Manager (AEM)
PDF
SPA Editor - Adobe Experience Manager Sites
PPTX
CQ Provisionning & Authoring
PDF
Web, Mobile, App and Back!
PDF
Drive dam
PDF
Optimizing HTML5 Sites with CQ5/WEM
PDF
CQ 5.4 Deep-Dive
PDF
Crx 2.2 Deep-Dive
Managing Omnichannel Experiences with Adobe Experience Manager (AEM)
Modernizing Adobe Experience Manager (AEM)
SPA Editor - Adobe Experience Manager Sites
CQ Provisionning & Authoring
Web, Mobile, App and Back!
Drive dam
Optimizing HTML5 Sites with CQ5/WEM
CQ 5.4 Deep-Dive
Crx 2.2 Deep-Dive

Recently uploaded (20)

PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Transform Your Business with a Software ERP System
PPTX
history of c programming in notes for students .pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
medical staffing services at VALiNTRY
Patient Appointment Booking in Odoo with online payment
Adobe Illustrator 28.6 Crack My Vision of Vector Design
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Navsoft: AI-Powered Business Solutions & Custom Software Development
Designing Intelligence for the Shop Floor.pdf
Complete Guide to Website Development in Malaysia for SMEs
How to Choose the Right IT Partner for Your Business in Malaysia
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Transform Your Business with a Software ERP System
history of c programming in notes for students .pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Salesforce Agentforce AI Implementation.pdf
medical staffing services at VALiNTRY

AEM Sightly Deep Dive

  • 1. Adobe Experience Manager @GabrielWalt, Product Manager Deep Dive into Sightly,
 an open source templating language
  • 2. Adobe Experience Manager Specification and TCK open sourced to GitHub.
 Reference implementation donated to Apache Sling. Follow @sightlyio on Twitter.
 http://docs.adobe.com/docs/en/aem/6-2/develop/sightly.html
  • 3. Adobe Experience Manager § 1 Expression contexts § 2 Passing data to client libs § 3 Use statement § 4 Template & Call statements § 5 Parameters for sub-resources
  • 4. Adobe Experience Manager The context option offers control over escaping and XSS protection. Allowing some HTML markup (filtering out scripts)
 <div>${properties.jcr:description @ context='html'}</div> Adding URI validation protection to other attributes than src or href
 <p data-link="${link @ context='uri'}">text</p> Display Context Option
  • 5. Adobe Experience Manager Most useful contexts and what they do: number XSSAPI.getValidNumber uri XSSAPI.getValidHref (default for src and href attributes) attribute XSSAPI.encodeForHTMLAttribute (default for other attributes) text XSSAPI.encodeForHTML (default for element content) scriptString XSSAPI.encodeForJSString styleString XSSAPI.encodeForCSSString html XSSAPI.filterHTML unsafe disables all protection, use at your own risk. Display Context Option <a href="${myLink}" title="${myTitle}">${myContent}</a>
 <script> var foo = "${myVar @ context='scriptString'}"; </string>
 <style> a { font-family: "${myFont @ context='styleString'}"; } </style> safer
  • 6. Adobe Experience Manager Preferred method for each context: – src and href attributes: number, uri, attribute, unsafe – other attributes: number, uri, attribute, unsafe – element content: number, text, html, unsafe – JS scripts ⊛ : number, uri, scriptString, unsafe – CSS styles ⊛ : number, uri, styleString, unsafe
 ⊛ An explicit context is required for script and style contexts.
 Don’t set the context manually unless you understand what you are doing. Display Context Option <a href="${myLink}" title="${myTitle}">${myContent}</a>
 <script> var foo = "${myVar @ context='scriptString'}"; </string>
 <style> a { font-family: "${myFont @ context='styleString'}"; } </style>
  • 7. Adobe Experience Manager § 1 Expression contexts § 2 Passing data to client libs § 3 Use statement § 4 Template & Call statements § 5 Parameters for sub-resources
  • 8. Adobe Experience Manager <!-- template.html -->
 <div data-sly-use.logic="logic.js"
 data-json="${logic.json}"></div> /* logic.js */
 use(function () {
 return {
 json: JSON.stringify({
 foo: "bar",
 arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 })
 };
 }); Passing data to client libs
  • 9. Adobe Experience Manager <!-- template.html -->
 <script id="my-handlebar-template"
 type="text/x-handlebars-template"
 data-sly-include="handlebar.html"></script> <!-- handlebar.html -->
 <p>${properties.jcr:title}</p> Server-side JavaScript logic
  • 11. Adobe Experience Manager § 1 Expression contexts § 2 Passing data to client libs § 3 Use statement § 4 Template & Call statements § 5 Parameters for sub-resources
  • 12. Adobe Experience Manager Initializes a helper object.
 <div data-sly-use.logic="logic.js">${logic.hi}</div> Output:
 <div>Hello World</div> 
 
 
 
 Use Statement
  • 13. Adobe Experience Manager <!-- template.html -->
 <div data-sly-use.logic="logic.js">${logic.hi}</div> /* logic.js */
 use(function () {
 return {
 hi: "Hello World"
 };
 }); Like for the Sightly template, the objects available in the logic file are the same ones as in JSP with global.jsp Server-side JavaScript logic
  • 14. Adobe Experience Manager <!-- template.html -->
 <div data-sly-use.logic="Logic">${logic.hi}</div> /* Logic.java in component */
 package apps.my_site.components.my_component;
 import org.sling…sightly.WCMUsePojo; public class Logic extends WCMUsePojo {
 private String hi; @Override
 public void activate() throws Exception {
 hi = "Hello World";
 } public String getHi() {
 return hi;
 }
 } Javalogic When the Java files are located in the content repository, next to the Sightly template, only the class name is needed. POJOextendingWCMUse
  • 15. Adobe Experience Manager <!-- template.html -->
 <div data-sly-use.logic="com.foo.Logic">${logic.hi}</div> /* Logic.java in OSGi bundle */
 package com.foo;
 import javax.annotation.PostConstruct;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.models.annotations.Model; @Model(adaptables = Resource.class)
 public class Logic {
 private String hi; @PostConstruct
 protected void init() {
 hi = "Hello World";
 } public String getHi() {
 return hi;
 }
 } Javalogic AdaptablewithSlingModels When embedded in 
 an OSGi bundle, the fully qualified Java class name is needed. The Use-API accepts classes that are adaptable from Resource or Request.
  • 16. Adobe Experience Manager Model logic
 This logic is not tied to a template and is potentially reusable among components.
 It should aim to form a stable API that changes little, even in case of a full redesign. ➔ Java located in OSGi bundle View logic
 This logic is specific to the templates and is likely to change if the design changes.
 It is thus a good practice to locate it in the content repository, next to the template. ➔ JavaScript located in component 
 If components are to be maintained by front-end devs (typically with Brackets). ➔ Java located in component
 If performance is critical (e.g. when many requests are not cached by the dispatcher). What kind of Use-API?
  • 17. Adobe Experience Manager Start simple: first, no code! OSGi (Model) Resource API Page API Content Repository Component (View)Content Structure sling: resourceType Resource Template – Sling plays the role of the controller and resolves the sling:resourceType, deciding which component will render the accessed resource. – The component plays the role of the view and it’s Sightly template builds the corresponding markup. – The Resource and Page APIs play the role of the model, which are available from the template as variables.
  • 18. Adobe Experience Manager Add logic only where needed – Model Logic is needed only if the logic to access the data is different to what existing APIs provide. – View Logic is needed only when the template needs additional data preparation. OSGi (Model) Resource API Page API Model Logic Content Repository Component (View)Content Structure sling: resourceType data-sly-use Resource Template View Logic
  • 19. Adobe Experience Manager The logic can access the same variables than exist in the template. JavaScript:
 var title = properties.get("title"); Java extending WCMUse:
 String title = getProperties().get("title", String.class); Java with SlingModels:
 @Inject @Optional
 private String title; Use-API Bindings
  • 20. Adobe Experience Manager With the same notation as for template parameters, named parameters can be passed to the Use-API.
 <a data-sly-use.ext="${'Externalize' @ path='page.html'}"
 href="${ext.absolutePath}">link</a> Output:
 <a href="/absolute/path/to/page.html">link</a> Don’t pass variables that are part of the global binding (like properties or resource) as they can be accessed from the logic too. Use-API Parameters
  • 21. Adobe Experience Manager These parameters can then be read in from the various Use-API. JavaScript:
 var path = this.path; Java extending WCMUse:
 String path = get("path", String.class); Java with SlingModels (works only when adapting from Request):
 @Inject @Optional
 private String path; Use-API Parameters
  • 22. Adobe Experience Manager The use statement can also load data-sly-template markup snippets located in other files.
 <!-- library.html -->
 <template data-sly-template.foo="${@ text}">
 <span class="example">${text}</span>
 </template> <!-- template.html -->
 <div data-sly-use.library="library.html"
 data-sly-call="${library.foo @ text='Hi'}"></div> Output:
 <div><span class="example">Hi</span></div> Use with Template & Call
  • 23. Adobe Experience Manager § 1 Expression contexts § 2 Passing data to client libs § 3 Use statement § 4 Template & Call statements § 5 Parameters for sub-resources
  • 24. Adobe Experience Manager Declare and call a markup snippet with named parameters.
 <template data-sly-template.foo="${@ class, text}">
 <span class="${class}">${text}</span>
 </template> <div data-sly-call="${foo @ class='example',
 text='Hi'}"></div> Output:
 <div><span class="example">Hi</span></div> Template & Call Statements Defining template parametersDeclaring template name Template content Calling template by name Passing named parameters
  • 25. Adobe Experience Manager Advanced example of a recursive site map with template, call and list.
 <ol data-sly-template.listChildren="${@ page}"
 data-sly-list="${page.listChildren}">
 <li>
 <div class="title">${item.title}</div>
 <ol data-sly-call="${listChildren @ page=item}"></ol>
 </li>
 </ol> <ol data-sly-call="${listChildren @ page=currentPage}"></ol> Template & Call Statements
  • 26. Adobe Experience Manager § 1 Expression contexts § 2 Passing data to client libs § 3 Use statement § 4 Template & Call statements § 5 Parameters for sub-resources
  • 28. Adobe Experience Manager Thank you! • Documentation
 https://docs.adobe.com/docs/en/aem/6-2/develop/sightly.html • Specification
 https://github.com/Adobe-Marketing-Cloud/sightly-spec • REPL (Read-Eval-Print Loop) live Sightly execution environment
 https://github.com/Adobe-Marketing-Cloud/aem-sightly-repl
 @GabrielWalt, Product Manager