AEM Sites Developer Expert study materials
AEM Sites Developer Expert study resources

AEM Sites Developer Expert: Sling Models, HTL, and Client-Side Libraries

AEM Sites Developer Expert · Work through your exam, one topic at a time.

All guide sections

Sling Models, HTL, and Client-Side Libraries

Sling Models adapt resources to Java objects. Know @Model with adaptables (Resource, SlingHttpServletRequest), resourceType, and injection annotations (@ValueMapValue, @ChildResource, @OSGiService, @Self, @RequestAttribute). Understand default injection strategy, @PostConstruct, and the difference between request-scoped models (need request adaptable for request attributes) and resource-scoped models.

HTL (Sling HTML Template Language) is the safe templating layer: data-sly-use, data-sly-list, data-sly-test, data-sly-resource, data-sly-include, and data-sly-template/data-sly-call. HTL auto-escapes output by context; use context='html' only deliberately. Expression options like @ i18n support localization.

Clientlibs (cq:ClientLibraryFolder) group CSS/JS with categories and dependencies, included via data-sly-call or the page component. Understand js.txt/css.txt, allowProxy, and the clientlibs proxy servlet for /etc.clientlibs.

Traps: using @Model(adaptables=Resource.class) then trying to inject a request attribute (fails); forgetting resourceType causing a model to apply too broadly; HTL data-sly-test consuming the variable; clientlib dependency cycles; missing allowProxy breaking /etc.clientlibs delivery.

Worked example: a model with @Model(adaptables=SlingHttpServletRequest.class, resourceType="mysite/components/card") can inject both @ValueMapValue properties and @RequestAttribute values safely.

Rule of thumb: match adaptables to what you need to inject; HTL escapes by default-don't disable it without reason.