September 24, 2026

HTL Use-API: Binding Java and JavaScript Logic to Templates

HTL Use-API features

The Use-API is an easy way to bind logic to template elements. Use-API objects can be written in Java, JavaScript or both: business logic belongs in Java, and view-specific logic can be written in server-side JavaScript.

Example: passing parameters from a component

<div data-sly-use.myClass="${'com.myproject.components.MyTestComponent' @ firstName='John', lastName='Miller'}">
    ${myClass.fullname}
</div>
import com.adobe.cq.sightly.WCMUsePojo;

public class MyTestComponent extends WCMUsePojo {

    // Combine the firstName and lastName
    public String getFullname() {
        return get("firstName", String.class) + " " + get("lastName", String.class);
    }
}
Use-API pros and cons

For new components, Sling Models are the recommended alternative to WCMUsePojo.

Back to the HTL tutorial index