Hello Community,
Wanted to understand if there is a possibility in AEM to check a cookie and load a sightly tag.
My use case
<sly data-sly-test="${properties.something == 'true'}">
<script>
Cookie condition check only if true execute the below
<div data-sly-test="${properties.something }" data-sly-unwrap>
<script type="text/javascript" src="${properties.script}"></script>
</div>
</script >
</sly>
Solved! Go to Solution.
I am not sure if you can do it from front end because the sightly code. But you can do it with Server side JS USE API
-------- script.js -------------
// Server-side JavaScript to get Coookie
use(function () {
var cookie = request.getCookie("wcmmode");
var cookieFound=false;
if(cookie!=null && cookie.value=="edit"){
cookieFound = true;
}
return {
cookieVal: cookie.value,
cookieFound:cookieFound
};
});
-------- Sightly code --------------
<sly data-sly-use.cObj="script.js" data-sly-test="${cObj.cookieFound }">
${cObj.cookieVal}
</sly>
Views
Replies
Total Likes
This is very easy. Use Sling Model and use Java logic to check a cookie. Setting and Reading Cookies : Cookie « Servlets « Java
Then set a field in the Sling Model based on the value.
Thanks Joeb,
I understand we could do a condition from backend , but we are using CDN for caching our pages . So whatever is cached first that experience would be shown, that is the reason we are looking for a front end solution.
Views
Replies
Total Likes
Views
Replies
Total Likes
I am not sure if you can do it from front end because the sightly code. But you can do it with Server side JS USE API
-------- script.js -------------
// Server-side JavaScript to get Coookie
use(function () {
var cookie = request.getCookie("wcmmode");
var cookieFound=false;
if(cookie!=null && cookie.value=="edit"){
cookieFound = true;
}
return {
cookieVal: cookie.value,
cookieFound:cookieFound
};
});
-------- Sightly code --------------
<sly data-sly-use.cObj="script.js" data-sly-test="${cObj.cookieFound }">
${cObj.cookieVal}
</sly>
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies