How to access a request paramater from the page url in HTL(sightly)

Avatar

Avatar

rohitn62196663

Avatar

rohitn62196663

rohitn62196663

26-09-2016

I am converting a component from JSP to HTL(Sightly). In the existing jsp file we are getting the req paramater using the following code:
request.getAttribute("urlAttr");

Similarily, I want to access the above url request paramater using sighlty tags. Is there any sightly tag to get the current request object and get the request params from that ?

I dont want to use the JAVA USE API for this one. I just want to do it in the html file itself using sightly tags so that I can avoid the server side code.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

6.0K

Likes

1.1K

Correct Reply

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

6.0K

Likes

1.1K

Correct Reply

1.1K
kautuk_sahni
Community Manager

27-09-2016

Hi 

You can use the following:

${request.requestParameterMap['test'][0].toString}

With http://server:port/resource?test=hello, then the output is ‘hello’

Source :- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

 

OR by using "Class implementing the Use interface" OR " Class extending WCMUsePojo class" OR "Class adaptable from Resource" OR "ling Models"

Source :- http://blogs.adobe.com/experiencedelivers/experience-management/htl-intro-part-4/

~kautuk

Answers (4)

Answers (4)

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

6.0K

Likes

1.1K

Correct Reply

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

6.0K

Likes

1.1K

Correct Reply

1.1K
kautuk_sahni
Community Manager

28-09-2016

+ 1 with Scott,

                
 Java Use-APIJavaScript Use-API
Pros
  • faster
  • can be inspected with a debugger
  • easy to unit-test
  • can be modified by front-end developers
  • is located within the component, keeping the view logic of a component close to it's corresponding template
Cons
  • cannot be modified by front-end developers
  • slower
  • no debugger (yet)
  • harder to unit-test

 

Source :- https://docs.adobe.com/docs/en/htl/docs/use-api.html

~kautuk

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

27-09-2016

Using Java - you can do a lot of tasks, Think of using a HTL as a component that divides view and model/controller (MVC). The HTML should be a thin as possible and you can use Java to control the model and controller logic. Having said that - for those reading this and want to know how to create a HTL component that uses WCMUsePojo - see: 

http://scottsdigitalcommunity.blogspot.com/2016/07/creating-aem-html-template-language.html

There is a 6.1, 6.2 and video included here. 

Avatar

Avatar

rohitn62196663

Avatar

rohitn62196663

rohitn62196663

27-09-2016

Thanks for the suggestion. I will try that. 

I am aware of the second approach i.e. java class but I dont want to use that just to get the req params from request object.

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

27-09-2016

In your example you have two different things... request attribute and request parameter.

Which one do you want to access in your code?