Hi @javedkh
Yes, there are ways to generate the correct clientlib URL in your sling model using AEM API's,
Instead of HTL constructs.
You can inject the HtmlLibraryManager OSGi service into your Sling Model and call its getLibraryUrl method.
import com.adobe.granite.ui.clientlibs.HtmlLibraryManager;
import com.adobe.granite.ui.clientlibs.LibraryType;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import javax.annotation.PostConstruct;
@Model(adaptables = ResourceResolver.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ClientLibPathModel {
@Self
private ResourceResolver resourceResolver;
@OSGiService
private HtmlLibraryManager htmlLibraryManager;
private String clientlibPath;
@PostConstruct
protected void init() {
if (htmlLibraryManager != null) {
clientlibPath = htmlLibraryManager.getLibraryUrl(resourceResolver, "category-name", LibraryType.JS);
}
}
public String getClientlibPath() {
return clientlibPath;
}
}Hope this helpful....:)
Regards,
Karishma.