May 12, 2020
Estimated Post Reading Time ~

HTML Template Language(Sightly) + Interview Questions

The purpose of HTML Template Language (HTL), supported by Adobe Experience Manager (AEM), is to offer a highly productive enterprise-level web framework that increases security and allows HTML developers without Java knowledge to better participate in AEM projects.

The HTML Template Language has been introduced with AEM 6.0, and takes the place of JSP (JavaServer Pages) as the preferred and recommended server-side template system for HTML. For web developers who need to build robust enterprise websites, the HTML Template Language helps to achieve increased security and development efficiency.

Interview Questions
Note: For more on sightly watch this video

1. What is advantages of sightly/HTML Template Language?
The HTML Template Language has been introduced with AEM 6.0, and takes the place of JSP (JavaServer Pages) as the preferred and recommended server-side template system for HTML. Folowing are the benefits of HTML Template Language
  • Increased Security - The HTML Template Language increases the security of sites that use it in their implementation, as compared to JSP and to most other template systems, because HTL is capable of automatically applying the proper context-aware escaping to all variables being output to the presentation layer. HTL makes this possible because it understands the HTML syntax, and uses that knowledge to adjust the required escaping for expressions, based on their position in the markup. This will for instance result in expressions placed in href or src attributes to be escaped differently from expressions placed in other attributes, or elsewhere.
  • While the same result can be achieved with template languages like JSP, there the developer must manually ensure that the proper escaping is applied to each variable. As a single omission or mistake on the applied escaping is potentially sufficient to cause a cross-site scripting (XSS) vulnerability, we decided to automate this task with HTL.
  • Simplified Development - The HTML Template Language is easy to learn and its features are purposely limited to ensure that it stays simple and straight-forward.
  • Reduced Costs - Increased security, simplified development and improved team collaboration, translates for AEM projects in reduced effort, faster time to market (TTM), and lower total cost of ownership (TCO). Read more
2. What are the Use-API in sightly?
Java Use-API - The HTML Template Language (HTL) Java Use-API enables a HTL file to access helper methods in a custom Java class. This allows all complex business logic to be encapsulated in the Java code, while the HTL code deals only with direct markup production. Read more

JavaScript Use-API
- The HTML Template Langugae (HTL) JavaScript Use-API enables a HTL file to access helper code written in JavaScript. This allows all complex business logic to be encapsulated in the JavaScript code, while the HTL code deals only with direct markup production. Read more

3. How to call service in Java Use-API class?
Use SlingScriptHelper.getService() method (into Java Use-API class)
SampleService service=getSlingScriptHandler().getService(SampleService.class);

4. What is the use of unwrap, element and attribute attribute in sightly?
Attribute attribute - Use an array to make things easy. Example
     attrMap = {
     title: "myTitle",
     class: "myClass",
     id: "myId"
     }
      <div data-sly-attribute="${attrMap}"></div>       <div title="myTitle" class="myClass" id="myId"></div>

  • Element attribute - Replaces the element of the host element
  • Unwrap attribute - Remove the outer elements (i.e. HTML Tags) leaving just the output of the Expression)
5. What are the implicit object present in sightly?
Without having to specify anything, HTL provides access to all objects that were commonly available in JSP after including global.jsp. These objects are in addition to any that may be introduced through the Use-API.

Enumerable Objects :
These objects provide convenient access to commonly used information. Their content can be accessed with the dot notation, and they can be iterated-through using data-sly-list or data-sly-repeat.


6. Difference between Sightly and JSP
Sightly Offers below advantages over JSP for better development in AEM
  • Protection against cross-site scripting injection.
  • Easily development of AEM Projects by front-end developers.
  • Flexible and powerful templating and logic binding features
  • Need to write less code in Sightly thus productivity increases.
  • A wider range of implicit objects as compared to JSP.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.