request.getAttribute in Sightly expression | Community
Skip to main content
November 12, 2015
Solved

request.getAttribute in Sightly expression

  • November 12, 2015
  • 4 replies
  • 7048 views

I have a site where we're setting some request attributes that are used across the whole page via a JS-use file:

// requestAttributes.js

use(function(){

    request.setAttribute('testAttribute","test attribute value");

});

And sightly markup that looks like this

<sly data-sly-use.atts="requestAttributes.js">

    <html>

        <sly data-sly-include="head.html" data-sly-unwrap/>

        <sly data-sly-include="body.html" data-sly-unwrap/>

        <sly data-sly-include="footer.html" data-sly-unwrap/>

    </html>

</sly>

 

Is there a way to access the request attributes natively in Sightly (i.e. ${request.attributes["testAttribute"]})?  I know that I could write a second js-use file to act as a getter for retrieving the attribute value, but ideally I'd like to do access it straight from the markup rather than having data-sly-use files in all of my include files.

 

Thanks!

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

Hi jmccoskery

As mentioned by Scott and Praveen, you can go through the article mentioned by them.

Apart from the article mentioned by then here are few more reference article that can be looked upon :-

Link:- http://aempodcast.com/2015/sightly/emulating-requestscope-variables-sightly-aem/#.VkWQ6LcrLRY

Link:- http://labs.6dglobal.com/blog/2015-01-23/accessing-request-variables-sightly/

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

Link:- http://stackoverflow.com/questions/25430981/are-there-requestscope-variables-in-sightly

I hope this would help you.

 

Thanks and Regards

Kautuk Sahni

4 replies

smacdonald2008
November 12, 2015
edubey
November 12, 2015
kautuk_sahni
Community Manager
kautuk_sahniCommunity ManagerAccepted solution
Community Manager
November 13, 2015

Hi jmccoskery

As mentioned by Scott and Praveen, you can go through the article mentioned by them.

Apart from the article mentioned by then here are few more reference article that can be looked upon :-

Link:- http://aempodcast.com/2015/sightly/emulating-requestscope-variables-sightly-aem/#.VkWQ6LcrLRY

Link:- http://labs.6dglobal.com/blog/2015-01-23/accessing-request-variables-sightly/

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

Link:- http://stackoverflow.com/questions/25430981/are-there-requestscope-variables-in-sightly

I hope this would help you.

 

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
dan_klco
February 22, 2018

FYI since labs.6dgloba.com is down, here's a link to the same post about accessing request variables in Sightly (HTL) on my personal blog: https://www.danklco.com/posts/2015/01/23/accessing-request-variables-sightly/