I am trying to get attribute value set in Slingmodel class. Below code is used to set value of attribute "mycustomparam" in sling model.
model1.java
request.setAttribute("mycustomparam", "value");
But unable to get this value in HTL
I have tried
${request.attribute @ mycustomparam}
In other model2.java, i am able to get this value using request.getAttribute('mycustomparam');
Is there any way to get value in sightly instead of model?
Views
Replies
Total Likes
Could you please check this https://www.linkedin.com/pulse/aem-63-request-attributes-ronak-bhayani/ if it helps.
Seems there isn't a way to directly access the request attributes in sightly and requires JS Use API. Here's a super short sample code to do just that: https://gist.github.com/gabrielwalt/a6a022ee65b3839d08bb4deb59211e57
@Nikhil_Verma yup there is no way to access request getattribute directly in sightly. We can use either js or separate model to get setted value.
why don't you write a get method to export attribute value in Sling Model to get the value in HTL?
e.g.
private mycustomparam;
request.setAttribute("mycustomparam", value);
mycustomparam = value;
public String getMycustomparam(){
return mycustomparam;
}
@arunpatidar Use case is different. I need to set value in request parameterin model1.java andneed this value in different model model2, which si working fine in my implemenation.
Thanks
Heena
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies