SlideShare a Scribd company logo
Introduction to Sightly and Sling Models in AEM6
Stefano Celentano
2
• What is Sightly?
• Why Sightly?
• Separation of concerns
• Comparing JSP and Sightly development
• Sightly features
• Sightly: the basics of the language
• Not a silver bullet
• Sightly and Sling Models
• An amazing combination
• Basic usage
• Learning from experience
• wcm-io and ACS Commons libraries
• Useful links
• A few hands-on examples
Summary
3
• New secure server-side HTML Templating Language introduced with AEM6 for
efficient development
• “Sightly” (meaning “pleasing to the eye”)
• “Alternative” to JSP
• Specification and TCK open sourced to GitHub
• Reference Adobe implementation donated to Apache Sling by Adobe (September
2014)
• Sightly reference implementation has been folded into Apache Sling project
• org.apache.sling.scripting.sightly
• org.apache.sling.xss
What is Sightly
4
Why Sightly: before…

Recommended for you

AEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveAEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep Dive

RichText Editor (RTE) is an integral component of AEM and it provides AEM authors a WYSIWYG text-editing experience on the web pages. RTE offers diverse configurations to developers. This presentation provides an in-depth understanding of this component and shows various concepts, use-cases, modes, configurations, best practices, limitations and troubleshooting that surround it. E-Seminar recording published here - https://helpx.adobe.com/experience-manager/kt/eseminars/gems/AEM-Rich-Text-Editor-RTE-Deep-Dive1.html

aemrterichtext editor
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2

This document provides an overview of key features in Sightly, an HTML templating language used in Adobe Experience Manager (AEM): - It describes Sightly statements like data-sly-use, data-sly-attribute, data-sly-element, and data-sly-resource that allow manipulating elements, attributes, and including resources. - Expression options like @context, @format, @join, and @i18n that control output are also covered. - URI manipulation using options like @scheme, @domain, @path, @query, and @fragment is explained. - Other topics include template and call statements, external templates, and the

advancedcq5htl
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM

A presentation given at the adaptTo() 2014 tech meetup on the topic of developing dynamic AEM components using concepts borrowed from the SPA philosophy.

aemspasoftware
5
Why Sightly: …after!
6
The standard workflow:
• Front end developers create HTML mark up, designs with all necessary client side
libraries
• (AEM) back end developers take this well formed, high-fidelity static HTML
“prototype”
• Systematically split the whole template in pieces
• Put it together again as JSP templates and components
• Add custom business logic inside JSP templates and components
This leads to well known issues:
• The process of splitting and putting together is error prone
• The process itself is time consuming
• This way of development does not provide good (and simple) separation of concerns
between UI and business logic
• As front end developers can’t easily maintain JSPs, they don’t develop new
components “inside” AEM
• They don’t directly cope with components issues in Author mode
(both visualization and UI issues)
Why Sightly: separation of concerns
7
Why Sightly: separation of concerns
8
Why Sightly: separation of concerns

Recommended for you

Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components

Components for AEM Sites that cover the most common web content needs. Discover which components exist, what features they offer, how they work technically and how they can be extended by a developer.

adobeadobe experience manageraem
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat

This document discusses using Sling Models with Sightly and JSP templates in AEM. It provides an overview of Sling Models, including their purpose, design goals, and key annotations. It also describes the standard injectors available in Sling Models and how to create custom injectors. The document outlines how to add Sling Model dependencies and use Sling Models within JSP and Sightly templates, including code examples. It concludes with a demonstration of Sling Models in action and information for appendix materials and questions.

AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101

This document discusses single page applications (SPAs) and their relationship with content management systems (CMS) like Adobe Experience Manager (AEM). It provides background on the shift from traditional websites to SPAs, outlines benefits and challenges of SPAs for both IT and marketing teams, and describes how AEM 6.4 aims to support content delivery to various channels including SPAs through a decoupled architecture.

content managementdigital asset managementdam
9
Why Sightly: comparing JSP and Sightly
10
Why Sightly: comparing JSP and Sightly
11
Why Sightly: comparing JSP and Sightly
12
Why Sightly: comparing JSP and Sightly

Recommended for you

Osgi
OsgiOsgi
Osgi

OSGI is a Java framework that implements a dynamic component model. It allows modular Java applications to be built from separate bundles that can be loaded, started, stopped and updated independently. Key aspects include: - Bundles are JAR files with additional configuration that can be loaded and stopped independently without affecting other bundles. - Services allow bundles to publish and discover capabilities via a registry. Dependencies between bundles are resolved dynamically. - The OSGi framework provides a lifecycle to manage the loading, starting and stopping of bundles. - Annotations like @Component, @Service and @Reference allow defining OSGi components and services using declarative services. - The OSGi specification is implemented by frameworks like

osgiosgi with aemosgi basics
slingmodels
slingmodelsslingmodels
slingmodels

This document discusses Sling Models in AEM, including what they are, why they are useful, how to use them, and examples of Sling Model annotations. Sling Models allow mapping of Sling objects like resources and requests to plain Java objects using annotations. They reduce coding efforts and make code more maintainable by avoiding redundant code. The document covers the necessary dependencies, common annotations like @Model, @Inject, @Optional, and examples of injecting resources, child resources, and retrieving values from the request.

Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6

This document discusses integration patterns in Adobe Experience Manager (AEM), including using Sling Models for dependency injection and accessing resources from different locations through a single ResourceResolver. It provides examples of integrating with backend APIs, databases, file systems and forms using techniques like ResourceProviders, Sling Filters and custom SlingServlets. It also covers accessing files from bundles and the filesystem using BundleResourceProvider and FsResourceProvider respectively.

aem6sling modelssling
13
Why Sightly: comparing JSP and Sightly
• Writing custom tag lib is not easy
• Need to mantain both Java class and TLD
• Custom tag lib lifecycle is hard to understand and difficult to integrate
inside the templates
• Have you ever effectively used it for your projects?
JSP Sightly
Based on Published Standards / Open Source?Y (*) N Y
IDE Support? Y Y/N
Officially Documented / Supported? Y Y
Documented Extension Model? Y N
Includes XSS escaping? Y (**) Y
Allows Basic Logic? Y Y
Enables Bad Coding Practices? Y N
* Some proprietary TagLibs used for interacting with CQ
** Provided by additional tag libraries
14
Why Sightly: features
• Code-less language, forcing strict separation of concerns
• Powerful extension points with the Use-API
• Automatic contextual HTML escaping and XSS protection
• Automatically removes HTML attributes if value is empty
• Reuses HTML blocks for statements
15
Sightly: the basics of the language
Expression language example:
<a href=‘‘{properties.link || ‘#’}’’ title=‘‘{properties.jcr:title}’’>
${properties.jcr:description}
</a>
Features:
- Automatic contextual HTML escaping and XSS escaping (warning!)
- Fallback value if property is empty
- Remove HTML attribute if value is empty
16
Sightly: the basics of the language
• Sightly comments

• Expression language
${properties.myProperty}
• They can only be used in attribute values, comments or in element content
• Standard bindings are available as in JSPs
• Block statements
<div data-sly-include=‘‘another-template.html’’></div>

Recommended for you

Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks

The document provides tips and best practices for configuring multiple farms in AEM Dispatcher. Key points include: - Splitting the Dispatcher configuration into multiple farms based on different caching needs, such as separate farms for DAM assets and pages. - Configuring different caching parameters and cache folders for each farm to optimize caching behavior. - Handling cache invalidation requests and vanity URLs across multiple farms. - Different approaches for flushing caches from Author and multiple Publishers to Dispatchers, and avoiding race conditions. - Bypassing the Dispatcher cache for select clients by rewriting URLs to include parameters checked by the Dispatcher configuration.

tipsconfigurationdispatcher
AEM Asset and Tag API
AEM Asset and Tag APIAEM Asset and Tag API
AEM Asset and Tag API

Presentation done at 'Ask The Community Experts' webinar @Adobe in July 2018 which covers the topic of Asset and Tag APIs in Adobe AEM

adobe aemadobe cqtags
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQDynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQ

This document summarizes a presentation on developing dynamic components in AEM using single-page application concepts. It discusses how traditional approaches to dynamic components can be tricky when components need to communicate and update frequently. An SPA approach treats each component as a module that handles its own data fetching and updating independently via AJAX calls. On page load, the server returns only static markup and components get dynamic data by making POST requests to a controller returning JSON. This allows for perceived faster interactions and easier front-end/back-end separation compared to full page reloads. Examples demonstrate rendering templates, initialization scripts, and a sample controller class to retrieve and return dynamic component data.

netceteraaemadaptto
17
Sightly: the basics of the language
• Expression bindings:
• ${properties}
• ${pageProperties}
• ${inheritedPageProperties}
• ${request} Sling Request
• ${resource} Sling Resource
• ${currentPage} WCM Page
• ${currentDesign} WCM Design
• ${component} WCM Component
• ${wcmmode} WCM Mode
Access properties with dot
notation ${properties.foo}
To avoid complex expressions inside
templates, Sightly does not allow
passing arguments to function call.
Only zero argument calls are allowed
from templates.
18
Sightly: the basics of the language
• Options allow to manipulate the result of an expression, or to pass
arguments to block statements
• Everything after the @ are comma separated options:
${myVar @ optionOne, optionTwo}
• Examples:
• String formatting:
${‘Page {0} of {1}’ @ format=[current, total]}
• Internationalization:
${‘Page’ @ i18n}
• Array join:
${[‘one’, ‘two’] @ join=‘; ’}
19
Sightly: the basics of the language
• Display context
• Every expression in Sightly has a display context
• Display context depends on the location within the HTML structure
• Example: text node, attribute, …
• Sightly automatically detect the context of expressions and escape them appropriately (to
prevent XSS)
This is not true for script (JS) and style (CSS) contexts
In this case we should explicitly set the context
• Example
<a href="${properties.link}" title="${properties.title}">${properties.text}</a>
Three variables, three different contexts.
No explicit context setting is required in the above cases
20
Sightly: the basics of the language
• Display context option
• The context option offers control over escaping and XSS protection
• Explicit context must be set for style contexts:
<span style="color: ${properties.color @
context='styleToken'};">...</span>
• To safely output markup (filtering out scripts)
<div>${properties.richText @ context=‘html’}</div>
uses AntiSamy policy rules
The default antisamy configuration is present at /libs/cq/xssprotection/config.xml, which can
be overlaid with your custom config within /apps.
• Adding URI validation protection to other attributes than src or href
<p data-link=‘‘${link @ context=‘uri’}’’>text</p>

Recommended for you

The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture

The document outlines the six key steps to create a solid AEM architecture: 1. Get the overall picture right by defining where AEM fits within the broader solution and how it will integrate with other systems. AEM can serve as an umbrella system, provider system, or independent system. 2. Map features to AEM's capabilities and validate choices through proofs of concept if using additional products. Consider licensing. 3. Design a simple, flexible content structure that supports features like multilingual and allows for future growth. 4. Plan the integration approach, aiming to integrate as close to the browser as possible when exposing services from AEM. 5. Determine the deployment model in advance as it impacts design choices

adobe experience managerbest practiceblue print
Adobe AEM core components
Adobe AEM core componentsAdobe AEM core components
Adobe AEM core components

This was presented at Adobe's 'Ask the AEM Expert' Session. This session covered Introduction to the core components How to use and when to use the core components

adobe aemadobe cqsling models
AEM & eCommerce integration
AEM & eCommerce integrationAEM & eCommerce integration
AEM & eCommerce integration

Introduction to AEM-eCommerce Integration and implementation of custom AEM native commerce,. This also gives introduction to multiple AEM commerce components and Commerce APIs. Visit http://adobeaemclub.com to know more about it. Also you can follow our Github to get examples https://github.com/AEMClub/adobe-aem-club/tree/master/commerceexample

commerce apiaemecommerce
21
Sightly: the basics of the language
• Most useful contexts and what they do:
• uri To display links and paths (validates URI)
• attribute Encodes HTML special characters
• text Encodes HTML special characters
• scriptString Encodes characters that would break out the string
• styleString Validates CSS tokens. Outputs nothing if it fails
• html Filters HTML to meet AntiSamy policy rules, removing what doesn’t match
• unsafe Disable all escaping and XSS protections
22
Sightly: the basics of the language
• Block statements
• To keep markup valid, block statements are defined by data-sly-* attributes
that can be added to any element on the markup
• <input data-sly-STATEMENT=‘‘foo’’ />
• Block statements can have no value, a static value, or an expression
<input data-sly-STATEMENT=‘‘${bar}’’ />
• Despite using data-attributes, block statements are all executed on the
server and no data-sly-* attribute is sent to the client!
• Sightly block statements:
• Markup inclusion: Include, Resource
• Control flow: test, list, template, call
• Markup modification: unwrap, element, attribute, text
• Object initialization: use
23
Sightly: the basics of the language
• Template and call statements
• Similar to data-sly-include
• Main difference: you can pass parameters to the included template
• Templates must be declared and called from another template
• <data-sly-template> declares a template
<template data-sly-template.header> <div> my template </div> </template>
Defines a template called header
Notice: the host element are not output by Sightly. If you call this template the only printed
mark up will be
<div> my template </div>
• <div data-sly-call=‘‘header’’></div> calls the template header defined above
• Templates can be located in a different file
• Templates accept parameters
<template data-sly-template.two=‘‘${ @ title}’’> <h1>${title}</h1> </template>
<div data-sly-call=‘‘${two @ title=properties.jcr:title}’’></div>
24
Sightly: the basics of the language
• Unwrap statement
• Removes the host element while retaining its content
<div data-sly-unwrap> <h1> Title </h1> </div>
Output: <h1> Title </h1>
• Warning!
• Use unwrap only when there’s no other way to write your template
• Prefer adding statements to existing elements
• Templates can easily become difficult to read
• Unwrap can also be subject to condition
<div class=‘‘edit-md’’ data-sly-unwrap=‘‘${wcmmode.edit}’’>
Text
</div>
Output: Text in EDIT mode
Output in PREVIEW/PUBLISH mode: <div class=‘‘edit-md’’>
Text
</div>
• Use data-sly-test to remove the element content as well

Recommended for you

AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching

This presentation cover Adobe AEM Dispatcher security and CDN and browser caching. This presentation is the second part of a webinar on AEM Dispatcher: http://dev.day.com/content/ddc/en/gems/dispatcher-caching---new-features-and-optimizations.html Visit url above to view the whole presentation. Domique Pfister the primary engineer developing AEM Dispatcher covers the first part on new features.

cq5aemadobe systems
AEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene IndexesAEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene Indexes

Chetan Mehrotra, Senior Computer Scientist, and Alex Parvulescu, Senior Developer, Adobe presented on Jan 20, 2016. They describe the features of Oak Lucene indexes and how they can be used to get your queries perform better. In the second part we will talk about how asynchronous indexing works in general and how it can be monitored.To view the on-demand session go to: http://bit.ly/AEMGems1202016 or for the MP4 version http://bit.ly/AEMGemsMP41202016

oakaemapache sling
Dust.js
Dust.jsDust.js
Dust.js

The document discusses LinkedIn's adoption of the Dust templating language in 2011. Some key points: - LinkedIn needed a unified view layer as different teams were using different templating technologies like JSP, GSP, ERB. - They evaluated 26 templating options and selected Dust as it best met their criteria like performance, i18n support, and being logic-less. - Dust templates are compiled to JavaScript for client-side rendering and to Java for server-side rendering (SSR) through Google's V8 engine, allowing templates to work on both client and server. - SSR addresses challenges like SEO, supporting clients without JavaScript, and i18n by rendering

web developmenttemplatesjavascript
25
Sightly: the basics of the language
• Use statement: Sightly Javascript Use API. Enables a Sightly file to access
helper code written in Javascript.
• Initialize a helper objects
<div data-sly-use.logic=‘‘logic.js’’>${logic.value}</div>
Inside logic.js file
use(function()) {
return {
value: ‘‘Hello World’’
};
});
Output:
<div> Hello World </div>
• Use Javascript Use API only for very simple tasks (date formatting, text
formatting, simple conditional logic, …):
• Javascript Use API is server-side Javascript (some JS native features are not fully supported)
• Cannot be debugged
• Very hard to find errors
• It’s slow
• Very hard to write Javascript Use API code for more complex task (e.g., cycling on repository
nodes, calling external services, etc.)
26
Sightly: the basics of the language
• Use statement: Sightly Java Use API enables a Sightly file to access helper
methods in a custom Java class.
• POJO extending WCMUse class
• WCMUse has been deprecated from AEM 6.1
and replaced with WCMUsePojo which uses
the new Sightly API from Apache Sling
• Local Java class: when the Java files are located in the content repository,
next to the Sightly template, only the class name is required to call the logic
• Bundle Java class: the Java class must be compiled and deployed within
an OSGi bundle (recommended when Java code implements logic
common to many components)
27
Sightly: the basics of the language
• Many ways to do the same thing. But, what kind of Use-API is better?
• 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
Example: Java class retrieving information from a web service; Java class
implementing logic for computing the menu structure
• 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).
Example: code implementing logic to output certain css classes inside the
template mark up (e.g., list menu, with selected/non selected items)
28
Not a silver bullet
• Sightly is a good option to improve the maintanability of your AEM
components but…
• You should follow best practices and guidelines otherwise your template code can
explode easily
• data-sly-unwrap can be evil
• wrap author/preview version of HTML inside smaller templates to be included; this makes your
components easier to read
• avoid use context=‘‘unsafe’’
• It is not extensible with new block statements or options
• Can be hard to debug
• <img data-sly-use.logic=‘‘foo.test.SomeLogic’’ data-sly-test=‘‘${logic.value}’’ >
• if the test is false, everything below img tag won’t be output; this can be hard to debug
• always use self closed elements
• Can lead to many Use API files containing the same logic
• Before implementing a new one, think about a common class extending WCMUse or Sling Model
• Can be frustrating, sometimes
• Write Use API external code even for the easy tasks
• Follow a style guide: https://github.com/Netcentric/aem-sightly-style-guide

Recommended for you

Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design

The document outlines an agenda for a session on HTML, CSS, and UI/UX design. It includes a quick revision of HTML and CSS standards and practices. It introduces HTML5 best practices regarding semantic elements. It defines what UI/UX is and why it is important. It discusses some UI principles to follow, such as keeping designs simple, straightforward, and focused on context while guiding users and providing feedback.

html5ux/uiui principles
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012

This document provides an overview of an upcoming training on Oracle Universal Content Management (UCM) 11g and Site Studio. It introduces the instructor, Lee Klement, and outlines the agenda for the three day training, which will cover topics such as deploying dynamic web sites, Site Studio administration, creating custom elements, using Idoc script, adding navigation, and more. Optional additional lessons may include creating fragments, working more with Idoc script, and Site Studio services.

ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015

An overall overview of Microsoft ASP.NET MVC Framework using C# Language and Entity Framework in Visual Studio 2015

mvcentityframeworkasp.net
29
Sightly and Sling Models: an amazing combination
• Sling Models are POJOs implementing the adapter pattern. They can be
automatically mapped from Sling objects
• Resource
• SlingHttpRequest
• Entirely annotation driven
• OOTB, support resource properties (implemented with ValueMap), SlingBindings,
OSGi services, request attributes
• Current latest version: 1.2.0
• AEM6+SP2 comes with 1.0.0
• Versions > 1.0.0 contain very useful features:
• 1.0.6: injector-specific annotations
• 1.1.0: @Self, @SlingObject, @ResourcePath annotations
• 1.2.0: Sling validation
30
Sightly and Sling Models: basic usage
package com.foo.core;
@Model(adaptables=Resource.class)
public class MyModel {
@Inject private String propertyName;
public String getResult() {
return ‘‘Hello World ’’ + propertyName;
}
}
• Class is annotated with @Model
• adaptbles option defines which types of objects are adaptable to this Sling Model
• Fields that need to be injected are annotated
In this case, propertyName is a property coming from the adapted resource
• Constructor injection (since 1.1.0)
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
public MyModel(@Named("propertyName") String propertyName) {
// constructor code
}
}
31
Sightly and Sling Models: basic usage
@Injected fields/methods are assumed to be required. To mark them as optional,
use @Optional:
@Model(adaptables=Resource.class)
public class MyModel {
@Inject @Optional
private String otherName;
}
A default value can be provided (for Strings & primitives):
@Model(adaptables=Resource.class)
public class MyModel {
@Inject @Default(values="defaultValue")
private String name;
}
32
Sightly and Sling Models: basic usage
OSGi services can be injected:
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
private ResourceResolverFactory resourceResolverFactory;
}
List injection for child resources works by injecting grand child resources (since
Sling Models Impl 1.0.6). For example, the class
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
private List<Resource> addresses;
}
addresses will contain address1 and address2

Recommended for you

Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty

Add-Ons are what make ExpressionEngine the flexible powerhouse that it is today. Being able to write your own simple plugins or incredibly expansive modules allows you to mold ExpressionEngine to nearly any task that your website might require. However, with that power comes a great responsibility to insure that your code is not slowing down the entire site or unduly stressing the server through bad code architecture. There are simple tools already built into ExpressionEngine and PHP that you can use to see precisely what your Add-On is doing during page processing and where it might be doing more work than is absolutely necessary. Every developer should use these to optimize their work from the very beginning of development, prior to release. This workshop will explain these tools and how you can use them effectively. It will also delve deeper into optimization techniques and tricks that will keep your code light and clean, while finding a balance between functionality and performance.

eecodephp
presentation
presentationpresentation
presentation

This document summarizes a talk on add-on development for ExpressionEngine. It discusses the three types of add-ons in EE - extensions, modules, and plugins. It covers important skills for add-on development like PHP, SQL, HTML/CSS, and JavaScript. It provides guidance on developing add-ons including researching existing approaches, mapping out features, designing database structures and template tags, and building the control panel. The document emphasizes best practices like following EllisLab development guidelines, proper commenting, sanitizing inputs, and using abstraction.

jquery tutorial
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js

Introduction Require JS Handlebars This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2014. http://www.ivanomalavolta.com

javascriptmobile application developmentmobile apps
33
Sightly and Sling Models: basic usage
The @PostConstruct annotation can be used to add methods which are invoked upon
completion of all injections:
@Model(adaptables=SlingHttpServletRequest.class)
public class MyModel {
@Inject
private PrintWriter out;
@Inject
@Named("log")
private Logger logger;
@PostConstruct
protected void sayHello() {
logger.info("hello");
}
}
34
Sightly and Sling Models: basic usage
Available injectors:
https://sling.apache.org/documentation/bundles/models.html#available-injectors
35
Sightly and Sling Models: basic usage
Injector-specific annotation vs normal annotations
Those annotations replace @Via, @Filter, @Named, @Optional, @Required, @Source and
@Inject. @Default may still be used in addition to the injector-specific annotation to set
default values. All elements given above are optional.
Annotation
Supported Optional
Elements
Injector
@ScriptVariable optional and name script-bindings
@ValueMapValue optional, name and via valuemap
@ChildResource optional, name and via child-resources
@RequestAttribute optional, name and via request-attributes
@ResourcePath optional, path, and name resource-path
@OSGiService optional, filter osgi-services
@Self optional self
@SlingObject optional sling-object
36
Sightly and Sling Models: client code
From a Sightly template:
<div data-sly-use.model=‘‘com.foo.core.MyModel’’>${model.result}</div>
From Java code:
MyModel model = resource.adaptTo(MyModel.class)

Recommended for you

AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)

We will talk about all aspects of building a single page application with AngularJS, and we will discuss real examples from day-to-day work. We will also cover a large amount of theory about general web development, best practices, and today's client demands. We will focus on three (3) main points: architecture, security, and real time notification.

angularjsjavascript
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź

This document discusses how Sightly and Slice can work together in AEM projects. Sightly provides a clear presentation layer for markup, while Slice leverages the Guice dependency injection framework. Models built with Slice can be used directly in Sightly templates via the data-sly-use attribute. This allows fine-grained control over objects while keeping Sightly templates clean. The key benefit of Slice is the standardized Guice dependency injection approach it provides.

presentation
presentationpresentation
presentation

This document discusses add-on development for ExpressionEngine. It covers what add-ons are, including extensions, modules, and plugins. It discusses necessary development skills like PHP, SQL, and HTML/CSS. It provides guidance on planning add-on development through researching, mapping features, designing templates and control panels. The document also covers writing code through following best practices, debugging, and improving performance. Developers are encouraged to turn on debugging, review queries, consider caching, remove deprecated code, and ask for help when needed.

jquery tutorial
37
Sightly and Sling Models: learning from experience
• Sling Models are instantiated everytime they are used with data-sly-use or adaptTo.
Issues can happen when the Sling Model instantiation includes connection to DB or web
service calls. Best practice: put Sling Model instance inside request object (in case the
same model is used within the same request).
• They can be hard to debug sometimes…
Since Sling Models 1.2.0 there is another way of instantiating models. The OSGi service
ModelFactory provides a method for instantiating a model that throws exceptions. This is
not allowed by the Javadoc contract of the adaptTo method. That way null checks are not
necessary and it is easier to see why instantiation of the model failed.
• Why Sling Models and NOT WCMUse
Sling Models are based on the adapter pattern
Dependency injection
Less simpler code
It’s a POJPO  unit testable
38
Sightly and Sling Models: ACS AEM commons and wcm.io
https://adobe-consulting-services.github.io/acs-aem-commons/features/aem-sling-models-
injectors.html
Allows for Sling Models classes and interfaces to be injected with common AEM-related
objects, namely those made available using <cq:defineObjects/>: resource,
resourceResolver, componentContext, pageManager, etc.
@Inject
private Page resourcePage;
http://wcm.io/sling/models/
Support injection request-derived context objects on all models, not only when the adaptable
is a request
39
• https://github.com/Adobe-Marketing-Cloud/aem-sightly-sample-todomvc/
Sightly TodoMVC Example
• https://github.com/Adobe-Marketing-Cloud/aem-sightly-repl
AEM Sightly Read–Eval–Print Loop
Useful links
40
• AEM 6 Project Archetype version 10
https://github.com/Adobe-Marketing-Cloud/aem-project-archetype
• AEM 6 Project bootstrap inside Eclipse + AEM Developer Tools for
Eclipse
http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html
1. Project overview
2. Automatic synch: FS  repo (both content package and bundle)
3. On demand synch: repo  FS
4. Change properties from Eclipse and automatic synch FS  repo
• Brackets
1. Syntax highlighting, auto completion (data-sly-* and variables used inside expression within
data attributes)
2. Automatic synch: FS  repo
3. On demand synch
• Archetype findings…
A few hands-on examples

Recommended for you

Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty

A presentation on Add-On Development: EE Expects that Every Developer will do his Duty as given at the EECI2009 conference in Leiden by Paul Burdick, lead developer at Solspace.

parenttoolboxsolspaceexpressionengine
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS

Introduction Require JS Handlebars Conclusions This presentation has been developed in the context of the Mobile Applications Development course, DISIM, University of L'Aquila (Italy), Spring 2015. http://www.ivanomalavolta.com

mobile application developmentmobile appsrequirejs
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016

How do you improve the quality of your existing software, while continuing to add value for your customers? What are some heuristics and code smells you can look for, and principles and patterns you can use to guide you, as you make your software better over time instead of worse? How can we improve our skills and techniques so that writing high quality software becomes our default, fastest way of working?

deviqrefactoringsolid principles
Thanks
Stefano Celentano
s.celentano@reply.it

More Related Content

What's hot

Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
DEEPAK KHETAWAT
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
Gabriel Walt
 
JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?
connectwebex
 
AEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveAEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep Dive
Hanish Bansal
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
Prabhdeep Singh
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
Bojana Popovska
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
Gabriel Walt
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
AEM HUB
 
AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101
Adobe
 
Osgi
OsgiOsgi
slingmodels
slingmodelsslingmodels
slingmodels
Ankur Chauhan
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
Yuval Ararat
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks
Ashokkumar T A
 
AEM Asset and Tag API
AEM Asset and Tag APIAEM Asset and Tag API
AEM Asset and Tag API
Lokesh BS
 
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQDynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Netcetera
 
The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture
Ashokkumar T A
 
Adobe AEM core components
Adobe AEM core componentsAdobe AEM core components
Adobe AEM core components
Lokesh BS
 
AEM & eCommerce integration
AEM & eCommerce integrationAEM & eCommerce integration
AEM & eCommerce integration
Lokesh BS
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
Andrew Khoury
 
AEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene IndexesAEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene Indexes
AdobeMarketingCloud
 

What's hot (20)

Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
 
SPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager SitesSPA Editor - Adobe Experience Manager Sites
SPA Editor - Adobe Experience Manager Sites
 
JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?
 
AEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep DiveAEM Rich Text Editor (RTE) Deep Dive
AEM Rich Text Editor (RTE) Deep Dive
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
Dynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEMDynamic components using SPA concepts in AEM
Dynamic components using SPA concepts in AEM
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101
 
Osgi
OsgiOsgi
Osgi
 
slingmodels
slingmodelsslingmodels
slingmodels
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Aem dispatcher – tips & tricks
Aem dispatcher – tips & tricksAem dispatcher – tips & tricks
Aem dispatcher – tips & tricks
 
AEM Asset and Tag API
AEM Asset and Tag APIAEM Asset and Tag API
AEM Asset and Tag API
 
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQDynamic Components using Single-Page-Application Concepts in AEM/CQ
Dynamic Components using Single-Page-Application Concepts in AEM/CQ
 
The six key steps to AEM architecture
The six key steps to AEM architectureThe six key steps to AEM architecture
The six key steps to AEM architecture
 
Adobe AEM core components
Adobe AEM core componentsAdobe AEM core components
Adobe AEM core components
 
AEM & eCommerce integration
AEM & eCommerce integrationAEM & eCommerce integration
AEM & eCommerce integration
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
 
AEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene IndexesAEM GEMs Session Oak Lucene Indexes
AEM GEMs Session Oak Lucene Indexes
 

Similar to Introduction to Sightly and Sling Models

Dust.js
Dust.jsDust.js
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
Karthikeyan Dhanasekaran CUA
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012
Lee Klement
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
reedmaniac
 
presentation
presentationpresentation
presentation
tutorialsruby
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
Ivano Malavolta
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź
AEM HUB
 
presentation
presentationpresentation
presentation
tutorialsruby
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
Leslie Doherty
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
Ivano Malavolta
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
Steven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin TimmermannO365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
NCCOMMS
 
Session 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design Patterns
PawanMM
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
murtazahaveliwala
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
Rui Quelhas
 
2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt
Chadharris42
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 

Similar to Introduction to Sightly and Sling Models (20)

Dust.js
Dust.jsDust.js
Dust.js
 
Html,CSS & UI/UX design
Html,CSS & UI/UX designHtml,CSS & UI/UX design
Html,CSS & UI/UX design
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
presentation
presentationpresentation
presentation
 
Handlebars and Require.js
Handlebars and Require.jsHandlebars and Require.js
Handlebars and Require.js
 
AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)AngularJS 1.x - your first application (problems and solutions)
AngularJS 1.x - your first application (problems and solutions)
 
When Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz NiedźwiedźWhen Sightly Meets Slice by Tomasz Niedźwiedź
When Sightly Meets Slice by Tomasz Niedźwiedź
 
presentation
presentationpresentation
presentation
 
Add-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his DutyAdd-On Development: EE Expects that Every Developer will do his Duty
Add-On Development: EE Expects that Every Developer will do his Duty
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin TimmermannO365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
O365Con18 - Using ARM Templates to Deploy Solutions on Azure - Kevin Timmermann
 
Session 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design Patterns
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
 
2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt2008_478_Lyons_ppt.ppt
2008_478_Lyons_ppt.ppt
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 

Recently uploaded

Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
MaisnamLuwangPibarel
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Sparity1
 
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
Hironori Washizaki
 
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdfdachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
DNUG e.V.
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
SSTech System
 
dachnug51 - All you ever wanted to know about domino licensing.pdf
dachnug51 - All you ever wanted to know about domino licensing.pdfdachnug51 - All you ever wanted to know about domino licensing.pdf
dachnug51 - All you ever wanted to know about domino licensing.pdf
DNUG e.V.
 
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial CompanyNBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Softwares
 
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
Semiosis Software Private Limited
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdfAWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
karim wahed
 
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
Roshan Dwivedi
 
Google ML-Kit - Understanding on-device machine learning
Google ML-Kit - Understanding on-device machine learningGoogle ML-Kit - Understanding on-device machine learning
Google ML-Kit - Understanding on-device machine learning
VishrutGoyani1
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
akshesh doshi
 
How we built TryBoxLang in under 48 hours
How we built TryBoxLang in under 48 hoursHow we built TryBoxLang in under 48 hours
How we built TryBoxLang in under 48 hours
Ortus Solutions, Corp
 
Shivam Pandit working on Php Web Developer.
Shivam Pandit working on Php Web Developer.Shivam Pandit working on Php Web Developer.
Shivam Pandit working on Php Web Developer.
shivamt017
 
Migrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS CloudMigrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS Cloud
Ortus Solutions, Corp
 
Folding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a seriesFolding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a series
Philip Schwarz
 
What is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for FreeWhat is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for Free
TwisterTools
 
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdfResponsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Trackobit
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
kalichargn70th171
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
ThousandEyes
 

Recently uploaded (20)

Development of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML TechnologiesDevelopment of Chatbot Using AI\ML Technologies
Development of Chatbot Using AI\ML Technologies
 
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptxAddressing the Top 9 User Pain Points with Visual Design Elements.pptx
Addressing the Top 9 User Pain Points with Visual Design Elements.pptx
 
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
COMPSAC 2024 D&I Panel: Charting a Course for Equity: Strategies for Overcomi...
 
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdfdachnug51 - HCL Sametime 12 as a Software Appliance.pdf
dachnug51 - HCL Sametime 12 as a Software Appliance.pdf
 
React Native vs Flutter - SSTech System
React Native vs Flutter  - SSTech SystemReact Native vs Flutter  - SSTech System
React Native vs Flutter - SSTech System
 
dachnug51 - All you ever wanted to know about domino licensing.pdf
dachnug51 - All you ever wanted to know about domino licensing.pdfdachnug51 - All you ever wanted to know about domino licensing.pdf
dachnug51 - All you ever wanted to know about domino licensing.pdf
 
NBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial CompanyNBFC Software: Optimize Your Non-Banking Financial Company
NBFC Software: Optimize Your Non-Banking Financial Company
 
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
React vs Next js: Which is Better for Web Development? - Semiosis Software Pr...
 
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdfAWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
AWS Cloud Practitioner Essentials (Second Edition) (Arabic) AWS Security .pdf
 
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
FAST Channels: Explosive Growth Forecast 2024-2027 (Buckle Up!)
 
Google ML-Kit - Understanding on-device machine learning
Google ML-Kit - Understanding on-device machine learningGoogle ML-Kit - Understanding on-device machine learning
Google ML-Kit - Understanding on-device machine learning
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
 
How we built TryBoxLang in under 48 hours
How we built TryBoxLang in under 48 hoursHow we built TryBoxLang in under 48 hours
How we built TryBoxLang in under 48 hours
 
Shivam Pandit working on Php Web Developer.
Shivam Pandit working on Php Web Developer.Shivam Pandit working on Php Web Developer.
Shivam Pandit working on Php Web Developer.
 
Migrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS CloudMigrate your Infrastructure to the AWS Cloud
Migrate your Infrastructure to the AWS Cloud
 
Folding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a seriesFolding Cheat Sheet #7 - seventh in a series
Folding Cheat Sheet #7 - seventh in a series
 
What is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for FreeWhat is OCR Technology and How to Extract Text from Any Image for Free
What is OCR Technology and How to Extract Text from Any Image for Free
 
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdfResponsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
Responsibilities of Fleet Managers and How TrackoBit Can Assist.pdf
 
A Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdfA Comparative Analysis of Functional and Non-Functional Testing.pdf
A Comparative Analysis of Functional and Non-Functional Testing.pdf
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
 

Introduction to Sightly and Sling Models

  • 1. Introduction to Sightly and Sling Models in AEM6 Stefano Celentano
  • 2. 2 • What is Sightly? • Why Sightly? • Separation of concerns • Comparing JSP and Sightly development • Sightly features • Sightly: the basics of the language • Not a silver bullet • Sightly and Sling Models • An amazing combination • Basic usage • Learning from experience • wcm-io and ACS Commons libraries • Useful links • A few hands-on examples Summary
  • 3. 3 • New secure server-side HTML Templating Language introduced with AEM6 for efficient development • “Sightly” (meaning “pleasing to the eye”) • “Alternative” to JSP • Specification and TCK open sourced to GitHub • Reference Adobe implementation donated to Apache Sling by Adobe (September 2014) • Sightly reference implementation has been folded into Apache Sling project • org.apache.sling.scripting.sightly • org.apache.sling.xss What is Sightly
  • 6. 6 The standard workflow: • Front end developers create HTML mark up, designs with all necessary client side libraries • (AEM) back end developers take this well formed, high-fidelity static HTML “prototype” • Systematically split the whole template in pieces • Put it together again as JSP templates and components • Add custom business logic inside JSP templates and components This leads to well known issues: • The process of splitting and putting together is error prone • The process itself is time consuming • This way of development does not provide good (and simple) separation of concerns between UI and business logic • As front end developers can’t easily maintain JSPs, they don’t develop new components “inside” AEM • They don’t directly cope with components issues in Author mode (both visualization and UI issues) Why Sightly: separation of concerns
  • 9. 9 Why Sightly: comparing JSP and Sightly
  • 10. 10 Why Sightly: comparing JSP and Sightly
  • 11. 11 Why Sightly: comparing JSP and Sightly
  • 12. 12 Why Sightly: comparing JSP and Sightly
  • 13. 13 Why Sightly: comparing JSP and Sightly • Writing custom tag lib is not easy • Need to mantain both Java class and TLD • Custom tag lib lifecycle is hard to understand and difficult to integrate inside the templates • Have you ever effectively used it for your projects? JSP Sightly Based on Published Standards / Open Source?Y (*) N Y IDE Support? Y Y/N Officially Documented / Supported? Y Y Documented Extension Model? Y N Includes XSS escaping? Y (**) Y Allows Basic Logic? Y Y Enables Bad Coding Practices? Y N * Some proprietary TagLibs used for interacting with CQ ** Provided by additional tag libraries
  • 14. 14 Why Sightly: features • Code-less language, forcing strict separation of concerns • Powerful extension points with the Use-API • Automatic contextual HTML escaping and XSS protection • Automatically removes HTML attributes if value is empty • Reuses HTML blocks for statements
  • 15. 15 Sightly: the basics of the language Expression language example: <a href=‘‘{properties.link || ‘#’}’’ title=‘‘{properties.jcr:title}’’> ${properties.jcr:description} </a> Features: - Automatic contextual HTML escaping and XSS escaping (warning!) - Fallback value if property is empty - Remove HTML attribute if value is empty
  • 16. 16 Sightly: the basics of the language • Sightly comments <!-- /* This will disappear from the output *--> • Expression language ${properties.myProperty} • They can only be used in attribute values, comments or in element content • Standard bindings are available as in JSPs • Block statements <div data-sly-include=‘‘another-template.html’’></div>
  • 17. 17 Sightly: the basics of the language • Expression bindings: • ${properties} • ${pageProperties} • ${inheritedPageProperties} • ${request} Sling Request • ${resource} Sling Resource • ${currentPage} WCM Page • ${currentDesign} WCM Design • ${component} WCM Component • ${wcmmode} WCM Mode Access properties with dot notation ${properties.foo} To avoid complex expressions inside templates, Sightly does not allow passing arguments to function call. Only zero argument calls are allowed from templates.
  • 18. 18 Sightly: the basics of the language • Options allow to manipulate the result of an expression, or to pass arguments to block statements • Everything after the @ are comma separated options: ${myVar @ optionOne, optionTwo} • Examples: • String formatting: ${‘Page {0} of {1}’ @ format=[current, total]} • Internationalization: ${‘Page’ @ i18n} • Array join: ${[‘one’, ‘two’] @ join=‘; ’}
  • 19. 19 Sightly: the basics of the language • Display context • Every expression in Sightly has a display context • Display context depends on the location within the HTML structure • Example: text node, attribute, … • Sightly automatically detect the context of expressions and escape them appropriately (to prevent XSS) This is not true for script (JS) and style (CSS) contexts In this case we should explicitly set the context • Example <a href="${properties.link}" title="${properties.title}">${properties.text}</a> Three variables, three different contexts. No explicit context setting is required in the above cases
  • 20. 20 Sightly: the basics of the language • Display context option • The context option offers control over escaping and XSS protection • Explicit context must be set for style contexts: <span style="color: ${properties.color @ context='styleToken'};">...</span> • To safely output markup (filtering out scripts) <div>${properties.richText @ context=‘html’}</div> uses AntiSamy policy rules The default antisamy configuration is present at /libs/cq/xssprotection/config.xml, which can be overlaid with your custom config within /apps. • Adding URI validation protection to other attributes than src or href <p data-link=‘‘${link @ context=‘uri’}’’>text</p>
  • 21. 21 Sightly: the basics of the language • Most useful contexts and what they do: • uri To display links and paths (validates URI) • attribute Encodes HTML special characters • text Encodes HTML special characters • scriptString Encodes characters that would break out the string • styleString Validates CSS tokens. Outputs nothing if it fails • html Filters HTML to meet AntiSamy policy rules, removing what doesn’t match • unsafe Disable all escaping and XSS protections
  • 22. 22 Sightly: the basics of the language • Block statements • To keep markup valid, block statements are defined by data-sly-* attributes that can be added to any element on the markup • <input data-sly-STATEMENT=‘‘foo’’ /> • Block statements can have no value, a static value, or an expression <input data-sly-STATEMENT=‘‘${bar}’’ /> • Despite using data-attributes, block statements are all executed on the server and no data-sly-* attribute is sent to the client! • Sightly block statements: • Markup inclusion: Include, Resource • Control flow: test, list, template, call • Markup modification: unwrap, element, attribute, text • Object initialization: use
  • 23. 23 Sightly: the basics of the language • Template and call statements • Similar to data-sly-include • Main difference: you can pass parameters to the included template • Templates must be declared and called from another template • <data-sly-template> declares a template <template data-sly-template.header> <div> my template </div> </template> Defines a template called header Notice: the host element are not output by Sightly. If you call this template the only printed mark up will be <div> my template </div> • <div data-sly-call=‘‘header’’></div> calls the template header defined above • Templates can be located in a different file • Templates accept parameters <template data-sly-template.two=‘‘${ @ title}’’> <h1>${title}</h1> </template> <div data-sly-call=‘‘${two @ title=properties.jcr:title}’’></div>
  • 24. 24 Sightly: the basics of the language • Unwrap statement • Removes the host element while retaining its content <div data-sly-unwrap> <h1> Title </h1> </div> Output: <h1> Title </h1> • Warning! • Use unwrap only when there’s no other way to write your template • Prefer adding statements to existing elements • Templates can easily become difficult to read • Unwrap can also be subject to condition <div class=‘‘edit-md’’ data-sly-unwrap=‘‘${wcmmode.edit}’’> Text </div> Output: Text in EDIT mode Output in PREVIEW/PUBLISH mode: <div class=‘‘edit-md’’> Text </div> • Use data-sly-test to remove the element content as well
  • 25. 25 Sightly: the basics of the language • Use statement: Sightly Javascript Use API. Enables a Sightly file to access helper code written in Javascript. • Initialize a helper objects <div data-sly-use.logic=‘‘logic.js’’>${logic.value}</div> Inside logic.js file use(function()) { return { value: ‘‘Hello World’’ }; }); Output: <div> Hello World </div> • Use Javascript Use API only for very simple tasks (date formatting, text formatting, simple conditional logic, …): • Javascript Use API is server-side Javascript (some JS native features are not fully supported) • Cannot be debugged • Very hard to find errors • It’s slow • Very hard to write Javascript Use API code for more complex task (e.g., cycling on repository nodes, calling external services, etc.)
  • 26. 26 Sightly: the basics of the language • Use statement: Sightly Java Use API enables a Sightly file to access helper methods in a custom Java class. • POJO extending WCMUse class • WCMUse has been deprecated from AEM 6.1 and replaced with WCMUsePojo which uses the new Sightly API from Apache Sling • Local Java class: when the Java files are located in the content repository, next to the Sightly template, only the class name is required to call the logic • Bundle Java class: the Java class must be compiled and deployed within an OSGi bundle (recommended when Java code implements logic common to many components)
  • 27. 27 Sightly: the basics of the language • Many ways to do the same thing. But, what kind of Use-API is better? • 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 Example: Java class retrieving information from a web service; Java class implementing logic for computing the menu structure • 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). Example: code implementing logic to output certain css classes inside the template mark up (e.g., list menu, with selected/non selected items)
  • 28. 28 Not a silver bullet • Sightly is a good option to improve the maintanability of your AEM components but… • You should follow best practices and guidelines otherwise your template code can explode easily • data-sly-unwrap can be evil • wrap author/preview version of HTML inside smaller templates to be included; this makes your components easier to read • avoid use context=‘‘unsafe’’ • It is not extensible with new block statements or options • Can be hard to debug • <img data-sly-use.logic=‘‘foo.test.SomeLogic’’ data-sly-test=‘‘${logic.value}’’ > • if the test is false, everything below img tag won’t be output; this can be hard to debug • always use self closed elements • Can lead to many Use API files containing the same logic • Before implementing a new one, think about a common class extending WCMUse or Sling Model • Can be frustrating, sometimes • Write Use API external code even for the easy tasks • Follow a style guide: https://github.com/Netcentric/aem-sightly-style-guide
  • 29. 29 Sightly and Sling Models: an amazing combination • Sling Models are POJOs implementing the adapter pattern. They can be automatically mapped from Sling objects • Resource • SlingHttpRequest • Entirely annotation driven • OOTB, support resource properties (implemented with ValueMap), SlingBindings, OSGi services, request attributes • Current latest version: 1.2.0 • AEM6+SP2 comes with 1.0.0 • Versions > 1.0.0 contain very useful features: • 1.0.6: injector-specific annotations • 1.1.0: @Self, @SlingObject, @ResourcePath annotations • 1.2.0: Sling validation
  • 30. 30 Sightly and Sling Models: basic usage package com.foo.core; @Model(adaptables=Resource.class) public class MyModel { @Inject private String propertyName; public String getResult() { return ‘‘Hello World ’’ + propertyName; } } • Class is annotated with @Model • adaptbles option defines which types of objects are adaptable to this Sling Model • Fields that need to be injected are annotated In this case, propertyName is a property coming from the adapted resource • Constructor injection (since 1.1.0) @Model(adaptables=Resource.class) public class MyModel { @Inject public MyModel(@Named("propertyName") String propertyName) { // constructor code } }
  • 31. 31 Sightly and Sling Models: basic usage @Injected fields/methods are assumed to be required. To mark them as optional, use @Optional: @Model(adaptables=Resource.class) public class MyModel { @Inject @Optional private String otherName; } A default value can be provided (for Strings & primitives): @Model(adaptables=Resource.class) public class MyModel { @Inject @Default(values="defaultValue") private String name; }
  • 32. 32 Sightly and Sling Models: basic usage OSGi services can be injected: @Model(adaptables=Resource.class) public class MyModel { @Inject private ResourceResolverFactory resourceResolverFactory; } List injection for child resources works by injecting grand child resources (since Sling Models Impl 1.0.6). For example, the class @Model(adaptables=Resource.class) public class MyModel { @Inject private List<Resource> addresses; } addresses will contain address1 and address2
  • 33. 33 Sightly and Sling Models: basic usage The @PostConstruct annotation can be used to add methods which are invoked upon completion of all injections: @Model(adaptables=SlingHttpServletRequest.class) public class MyModel { @Inject private PrintWriter out; @Inject @Named("log") private Logger logger; @PostConstruct protected void sayHello() { logger.info("hello"); } }
  • 34. 34 Sightly and Sling Models: basic usage Available injectors: https://sling.apache.org/documentation/bundles/models.html#available-injectors
  • 35. 35 Sightly and Sling Models: basic usage Injector-specific annotation vs normal annotations Those annotations replace @Via, @Filter, @Named, @Optional, @Required, @Source and @Inject. @Default may still be used in addition to the injector-specific annotation to set default values. All elements given above are optional. Annotation Supported Optional Elements Injector @ScriptVariable optional and name script-bindings @ValueMapValue optional, name and via valuemap @ChildResource optional, name and via child-resources @RequestAttribute optional, name and via request-attributes @ResourcePath optional, path, and name resource-path @OSGiService optional, filter osgi-services @Self optional self @SlingObject optional sling-object
  • 36. 36 Sightly and Sling Models: client code From a Sightly template: <div data-sly-use.model=‘‘com.foo.core.MyModel’’>${model.result}</div> From Java code: MyModel model = resource.adaptTo(MyModel.class)
  • 37. 37 Sightly and Sling Models: learning from experience • Sling Models are instantiated everytime they are used with data-sly-use or adaptTo. Issues can happen when the Sling Model instantiation includes connection to DB or web service calls. Best practice: put Sling Model instance inside request object (in case the same model is used within the same request). • They can be hard to debug sometimes… Since Sling Models 1.2.0 there is another way of instantiating models. The OSGi service ModelFactory provides a method for instantiating a model that throws exceptions. This is not allowed by the Javadoc contract of the adaptTo method. That way null checks are not necessary and it is easier to see why instantiation of the model failed. • Why Sling Models and NOT WCMUse Sling Models are based on the adapter pattern Dependency injection Less simpler code It’s a POJPO  unit testable
  • 38. 38 Sightly and Sling Models: ACS AEM commons and wcm.io https://adobe-consulting-services.github.io/acs-aem-commons/features/aem-sling-models- injectors.html Allows for Sling Models classes and interfaces to be injected with common AEM-related objects, namely those made available using <cq:defineObjects/>: resource, resourceResolver, componentContext, pageManager, etc. @Inject private Page resourcePage; http://wcm.io/sling/models/ Support injection request-derived context objects on all models, not only when the adaptable is a request
  • 39. 39 • https://github.com/Adobe-Marketing-Cloud/aem-sightly-sample-todomvc/ Sightly TodoMVC Example • https://github.com/Adobe-Marketing-Cloud/aem-sightly-repl AEM Sightly Read–Eval–Print Loop Useful links
  • 40. 40 • AEM 6 Project Archetype version 10 https://github.com/Adobe-Marketing-Cloud/aem-project-archetype • AEM 6 Project bootstrap inside Eclipse + AEM Developer Tools for Eclipse http://docs.adobe.com/content/docs/en/dev-tools/aem-eclipse.html 1. Project overview 2. Automatic synch: FS  repo (both content package and bundle) 3. On demand synch: repo  FS 4. Change properties from Eclipse and automatic synch FS  repo • Brackets 1. Syntax highlighting, auto completion (data-sly-* and variables used inside expression within data attributes) 2. Automatic synch: FS  repo 3. On demand synch • Archetype findings… A few hands-on examples

Editor's Notes

  1. The name “Sightly” (meaning “pleasing to the eye”) highlights its focus on keeping your markup beautiful, and thus maintainable, once made dynamic.
  2. This way of development does not provide good (and simple) separation of concerns between UI and business logic: in realtà I modi ci sarebbero: CUSTOM TAG LIBRARIES
  3. Il tempo per lo sviluppo dei component con l’utilizzo di JSP + logica Java all’interno è maggiore
  4. AUTOMATIC CONTEXTUAL HTML ESCAPING AND XSS PROTECTION: Sightly automatically filters and escapes all variables being output to the presentation layer to prevent cross-site-scripting (XSS) vulnerabilities. As Sightly understands the HTML syntax, it is capable to automatically detect the scope in which variables are placed, and automatically do proper context-aware escaping and XSS protection. Yet, it is possible to manually control the display context if needed. REUSES HTML BLOCKS FOR STATEMENTS: Sightly block statements are custom data attributes added directly to existing HTML. This allows easy and unobtrusive annotation of a prototype static HTML page, converting it to a functioning dynamic template without breaking the validity of the HTML code.
  5. The display context of a Sightly expression refers to its location within the structure of the HTML page. For example, if the expression appears in place that would produce a text node once rendered, then it is said to be in a text context. If it is found within the value of an attribute, then it is said to be in an attribute context, and so forth. With the exception of script (JS) and style (CSS) contexts, Sightly will automatically detect the context of expressions and escape them appropriately, to prevent XSS security problems. In the case of scripts and CSS, the desired context behavior must be explicitly set. Additionally, the context behavior can also be explicitly set in any other case where an override of the automatic behavior is desired. Here we have three variables in three different contexts: properties.link (uri context), properties.title (attribute context) and properties.text (text context). Sightly will escape each of these differently in accordance with the security requirements of their respective contexts. No explicit context setting is required in normal cases such as this one: <a href="${properties.link}" title="${properties.title}">${properties.text}</a>
  6. The display context of a Sightly expression refers to its location within the structure of the HTML page. For example, if the expression appears in place that would produce a text node once rendered, then it is said to be in a text context. If it is found within the value of an attribute, then it is said to be in an attribute context, and so forth. With the exception of script (JS) and style (CSS) contexts, Sightly will automatically detect the context of expressions and escape them appropriately, to prevent XSS security problems. In the case of scripts and CSS, the desired context behavior must be explicitly set. Additionally, the context behavior can also be explicitly set in any other case where an override of the automatic behavior is desired. Here we have three variables in three different contexts: properties.link (uri context), properties.title (attribute context) and properties.text (text context). Sightly will escape each of these differently in accordance with the security requirements of their respective contexts. No explicit context setting is required in normal cases such as this one: <a href="${properties.link}" title="${properties.title}">${properties.text}</a>
  7. Less code to write (only one annotation is necessary in most of the cases) More robust (in case of name collisions among the different injectors, you make sure that the right injector is used) Better IDE support (because the annotations provide elements for each configuration which is available for that specific injector, i.e. filter only for OSGi services)
  8. Why Sling Models and NOT WCMUse: https://www.cognifide.com/blogs/cq/sightly-and-slice---where-a-beautiful-markup-meets-a-beautiful-code/#.VgK7-d_tmko
  9. Why Sling Models and NOT WCMUse: https://www.cognifide.com/blogs/cq/sightly-and-slice---where-a-beautiful-markup-meets-a-beautiful-code/#.VgK7-d_tmko