Posts

Showing posts from November, 2024

@ScriptVariable in AEM

Image
In Apache Sling, @ScriptVariable is an annotation used in Sling Models to inject objects from the HTL (HTML Templating Language) script context into the model class. It is part of the Sling Models API and helps bridge the gap between the templating layer and backend logic by allowing developers to access various predefined or custom variables. Key Features of @ScriptVariable : Source Context : It pulls variables that are typically available in the HTL script context , such as currentPage , resource , or request . Type-Safe Access : The variable injected by @ScriptVariable is strongly typed, meaning the developer defines the type of the object to be injected. Simplifies Code : Reduces the need to manually retrieve these variables from the script context, leading to cleaner and more maintainable code. How It Works : HTL Context : Variables like currentPage are typically defined automatically in the HTL context when rendering a component or page. Example in HTL: < h1 > ${curre...