For AI agents: the complete documentation index is available at https://nhanbe.id.vn/llms.txt, the full documentation bundle is available at https://nhanbe.id.vn/llms-full.txt, and this page is available as Markdown at https://nhanbe.id.vn/aem/foundation/htl-templates.md.
HTL (formerly Sightly) is AEM's server-side template language. It completely replaces JSP and serves as the standard for rendering components. HTL's core philosophy is secure by default — automatically escaping output data to prevent XSS attacks.
Security Warning: NEVER use context='unsafe' unless completely certain content is safe. For Rich Text Editor (RTE) output, RTE sanitizes malicious code on save, and default html context provides extra protection on render. RTE output called via $\{model.richText\} is safe!
<!-- Set single attribute --><div data-sly-attribute.id="${model.anchorId}">Content</div><!-- Set multiple attributes via Map --><div data-sly-attribute="${model.attributes}">Content</div><!-- Conditional attribute (removed automatically if empty/false) --><input data-sly-attribute.disabled="${model.isDisabled ? 'disabled' : ''}"/>
Keeps inner content while unwrapping host HTML tag from DOM. Useful for logical wrappers without introducing unnecessary wrapper <div/> elements.
<div data-sly-unwrap> <p>This paragraph will not be wrapped in div in browser DOM.</p></div>
HTL templates automatically inject global objects:
Object
Type
Description
properties
ValueMap
Properties of current resource (JCR node).
pageProperties
ValueMap
Properties of current page (jcr:content node).
inheritedPageProperties
ValueMap
Inherited properties from ancestor pages.
currentPage
Page
Current AEM Page object.
currentNode
Node
Current JCR Node object.
resource
Resource
Current Sling Resource object.
request
SlingHttpServletRequest
Current HTTP request object.
response
SlingHttpServletResponse
Current HTTP response object.
log
Logger
Output log to AEM error.log.
wcmmode
WCMMode
Current UI mode (edit, preview, disabled).
currentStyle
Style
Current component Policy configuration.
Practical Example:
<!-- Get page title --><title>${currentPage.title || currentPage.name}</title><!-- Check Edit mode to render placeholder for authors --><div data-sly-test="${wcmmode.edit || wcmmode.preview}"> <p>Component is empty. Drag and drop data here.</p></div><!-- Print debug log -->${'Component rendering started' @ log}
@Model(adaptables = SlingHttpServletRequest.class)public class PaginationModel { @RequestAttribute private int currentPage; @RequestAttribute private int totalPages;}