Hi,
I have a query, can we write a condition to check the methods in the model class before we call the model class using data-sly-use and call the methods.
here's a scenario:
Model Class,
HTML file
Solved! Go to Solution.
Views
Replies
Total Likes
<section data-sly-use.model="com.bootcamp.core.models.HelloWorldModel" data-
message="${model.helloMessage}">
</section>
This is just fine, looks like you are using HTML attributes, which is consumed by the JS frontend code. you can detect whether data-message is null, blank or not, then perform the task as needed.
@Vinod-N-E it's recommended to write your logic on the sling model and assign a return value to a member variable and use that in HTL.
Thank you Manu, but could I some how do it in the front end as well.
@Vinod-N-E I believe, data-sly-use initializes your sling model, ie. it basically declares component-beans with this statement for instance, to check conditions before that may not be possible.
However, I am not sure what your use case is.
I understand what you mean, thank you for the help.
Easy,
<sly data-sly-use.model="com.bootcamp.core.models.HelloWorldModel"></sly>
<sly data-sly-test="${model.helloMessage}>${helloMessage}</sly>
This is helpful Brian, could you suggest me for a different secnario.
here's the scenario: take the example of the same model class above,
<section data-sly-use.model="com.bootcamp.core.models.HelloWorldModel" data-
message="${model.helloMessage}">
</section>
How do I write a test condition as an attribute for the section tag and execute the helloMessage method.
Thanks,
<section data-sly-use.model="com.bootcamp.core.models.HelloWorldModel" data-
message="${model.helloMessage}">
</section>
This is just fine, looks like you are using HTML attributes, which is consumed by the JS frontend code. you can detect whether data-message is null, blank or not, then perform the task as needed.
Thanks Brian, your answers were helpful.
Views
Likes
Replies
Views
Like
Replies