I have method with arguments in Sling model. while calling that method from HTL facing below issue in Log for passing parameters. please advise
public void createContentFragment(String parentPath, String fragmentName, String modelPath) {}
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
This is not supported. It is not possible to use parametrized method from Sling Model on HTL level.
What can be done, you can pass values/params during initialization phase via Request Attribute. So your class could look like below:
@Model(adaptables = {SlingHttpServletRequest.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class CFMImporter {
@RequestAttribute
private String parentPath;
@RequestAttribute
private String fragmentName;
@RequestAttribute
private String modelPath;
public void createContentFragment() {}
}
HTL:
<div data-sly-use.cfmGenModel="${'com.myproject.core.models.CFMImporter' @ parentPath='/content/dam/my-cfm', fragmentName='popup-fragment', modelPath='/conf/consumer-bau/settings/dam/cfm/models/bau-model-popup'}">
${cfmGenModel.createContentFragment}
</div>
Please also check below documentation:
It is not possible to achieve what you need in the way you want. There is still an open request for this, but me personally I don't think it will be implemented:
https://github.com/adobe/htl-spec/issues/86
The way to do it is how @lukasz-m suggested. That is the tipical approach.
The best approach would be to keep view sepatate from the controller, and not have hard-coded values in HTL. I advice to move the logic only in the model and have control over it via component properties. This means to have dialog fields to configure the component with stuff that will instruct your model to execute its logic for a given path, a given CF type and a given config.
Views
Replies
Total Likes
Views
Likes
Replies