Expand my Community achievements bar.

SOLVED

request.getAttribute in Sightly expression

Avatar

Level 1

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!

1 Accepted Solution

Avatar

Correct answer by
Administrator

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

View solution in original post

4 Replies

Avatar

Correct answer by
Administrator

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

Avatar

Level 5

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/