We have a requirement where we have created content fragment model having one of the fields as location title. Now we are getting list of content fragment objects (officeLocationCfms) in component HTL Code. We need to display content fragment location title value in component's UI.
Method: com.adobe.cq.dam.cfm.ContentFragment.getElement(String var1)
But its not working.
I wanted to know how to call parameterized methods from HTL.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @S_K_Agarwal ,
Try passing multiple parameters as mentioned below, for sample i have hardcoded parameter as string values here & replace these hardcoded value by dynamic values. please make sure datatype of dynamic value getting passed in sightly is same as datatype defined for @Inject variable in Sling Model class.
Sightly:
<sly data-sly-test.file="/some/path/to/file" data-sly-test.image="image">
<sly data-sly-use.helloWorldModel="${'com.project.HelloWorldModel' @fileReference=file, imgParam=image}"/>
</sly>
Sling Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class HelloWorldModel {
@Inject
private String fileReference;
@Inject
private String imgParam;
Hope this helps!
Thanks
Hi @S_K_Agarwal
I don't think it is possible to call parameterized method. We can only call getter non-parametrized methods as per my knowledge.
However I would recommend instead of calling your method in HTL, you should write business logic in your existing backend sling model class com.XXXXXX.core.components.models.ContactCards by calling
getElement(String var1) and send an updated list from the sling model and use that list in HTL.
Hi @S_K_Agarwal ,
Try passing multiple parameters as mentioned below, for sample i have hardcoded parameter as string values here & replace these hardcoded value by dynamic values. please make sure datatype of dynamic value getting passed in sightly is same as datatype defined for @Inject variable in Sling Model class.
Sightly:
<sly data-sly-test.file="/some/path/to/file" data-sly-test.image="image">
<sly data-sly-use.helloWorldModel="${'com.project.HelloWorldModel' @fileReference=file, imgParam=image}"/>
</sly>
Sling Model Class:
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class HelloWorldModel {
@Inject
private String fileReference;
@Inject
private String imgParam;
Hope this helps!
Thanks
Hi,
This is only possible if the parameter is injected to the model. I would suggest to check to retuen the title in the same model as map, because map support param
Example
List
[{"getOfficeLocationCfm":"/content/dam/myprj/cmf/.....","cmfTitle":"Hello"}]
HTL
Otherway is to pass the Cf path to HTL Model and get theTitle ,
e.g.
https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ParamModel.java
Views
Likes
Replies