May 10, 2020
Estimated Post Reading Time ~

HTL Global Objects, HTL Use-API

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 .

Variable Name                                            Description
properties                            List of properties of the current Resource. Backed by                                               org.apache.sling.api.resource.ValueMap
pageProperties                     List of page properties of the current Page. Backed by                                            org.apache.sling.api.resource.ValueMap
inheritedPageProperties         List of inherited page properties of the current Page.                                               Backed by org.apache.sling.api.resource.ValueMap

Java-backed Objects
Each of the following objects is backed by the corresponding Java object.
The most useful variables in the table below are highlighted in bold.

Variable Name                                Description
component                            com.day.cq.wcm.api.components.Component
componentContext                 com.day.cq.wcm.api.components.ComponentContext
currentDesign                        com.day.cq.wcm.api.designer.Design
currentNode                          javax.jcr.Node
currentPage                          com.day.cq.wcm.api.Page
currentSession                      javax.servlet.http.HttpSession
currentStyle                          com.day.cq.wcm.api.designer.Style
designer                               com.day.cq.wcm.api.designer.Designer
editContext                           com.day.cq.wcm.api.components.EditContext
log                                       org.slf4j.Logger
out                                       java.io.PrintWriter
pageManager                        com.day.cq.wcm.api.PageManager
reader                                  java.io.BufferedReader
request                                 org.apache.sling.api.SlingHttpServletRequest
resolver                                org.apache.sling.api.resource.ResourceResolver
resource                               org.apache.sling.api.resource.Resource
resourceDesign                     com.day.cq.wcm.api.designer.Design
resourcePage                        com.day.cq.wcm.api.Page
response                              org.apache.sling.api.SlingHttpServletResponse
sling                                    org.apache.sling.api.scripting.SlingScriptHelper
slyWcmHelper                      com.adobe.cq.sightly.WCMScriptHelper
wcmmode                            com.adobe.cq.sightly.SightlyWCMMode
xssAPI                                 com.adobe.granite.xss.XSSAPI

JavaScript-backed Objects
There are also objects available that are backed by JavaScript. However, as of AEM 6.2, these objects are still experimental and it is better to use the Java-backed objects, which allow doing the same.

HTL Use-API
The following table gives an overview of the pros and cons of each API.

For page components, it is recommended to use a mixed model, where all model logic is located in Java, providing clear APIs that are agnostic to anything that happens in the view (i.e. within the components). AEM comes with great default models like the Page or the Resource API that should be able to cover most cases.

All view logic that is specific to a component should be placed within that component as JavaScript because it belongs to that component.



By aem4beginner

No comments:

Post a Comment

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