Skip to main content
Level 3
Oct 16, 2015 2:29 AM UTC
Solved

Access request query string parameter in Sightly component

How do I access a request query string parameter in Sightly HTML. Do I have to expose it through the WCMUse model or can I just access it directly in the HTML?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:29 AM UTC

You can use the following:

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

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

8 replies

Level 2
Aug 28, 2019 7:13 PM UTC

Is it possible to return all the query string parameters? Similar to javascript window.location.search. Eg: current page url is https://google.com?utm_source=search&utm_media=online&param3=xxx and the expected return string is ?utm_source=search&utm_media=online&param3=xxx

Translate
Feike_Visser1
Employee
Nov 13, 2018 11:46 AM UTC
Level 2
Nov 12, 2018 7:54 AM UTC

Try this:

${request.parameterMap.test}

Translate
Feike_Visser1
Employee
Feb 11, 2018 12:39 PM UTC

Please note that there is an issue with this since AEM6.3+SP1+CFP1 (AEM6.3.1.1)

Workaround here: htl-examples/request-parameter.html at master · heervisscher/htl-examples · GitHub

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:29 AM UTC

See this Blog that talks about Sightly:

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

This talks about how to access the para­me­ters.

Translate
Level 3
Oct 16, 2015 2:29 AM UTC

These are request attributes, not query string attributes e.g. getParameter. How do I get a query string parameter e.g. ?query=some+query

Translate
francisco_ribei
Level 6
Oct 16, 2015 2:29 AM UTC

Once you have the SlingHttpRequest object you can get the parameters using request.getParameter method.

Have you tried that?

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:29 AM UTC

You can use the following:

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

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

Translate