Expand my Community achievements bar.

SOLVED

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

Avatar

Level 4

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.

1 Accepted Solution

Avatar

Correct answer by
Administrator

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



Kautuk Sahni

View solution in original post

5 Replies

Avatar

Correct answer by
Administrator

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



Kautuk Sahni

Avatar

Employee

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

Which one do you want to access in your code?

Avatar

Level 4

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

Level 10

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

Administrator

+ 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



Kautuk Sahni