Skip to main content
HeenaMadan
New Participant
August 9, 2022

request getattribute in Sightly set from slingmodel

  • August 9, 2022
  • 3 replies
  • 2984 views

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?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

arunpatidar
New Participant
August 10, 2022

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; }

 

Arun Patidar
HeenaMadan
New Participant
August 10, 2022

@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

Nikhil_Verma
New Participant
August 10, 2022

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

 

HeenaMadan
New Participant
August 10, 2022

@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.

DEBAL_DAS
New Participant
August 9, 2022