request.getAttribute in Sightly expression | Community
Skip to main content
New Participant
Nov 12, 2015 12:03 AM UTC
Solved

request.getAttribute in Sightly expression

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.
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Nov 13, 2015 7:30 AM UTC

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

4 replies

dan_klco
Level 4
Feb 22, 2018 10:10 PM UTC

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/

Translate
kautuk_sahni
kautuk_sahniAccepted solution
Employee
Nov 13, 2015 7:30 AM UTC

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

Translate
Kautuk Sahni
edubey
Level 10
Nov 12, 2015 1:28 AM UTC
smacdonald2008
Level 10
Nov 12, 2015 12:35 AM UTC