The cookie value cannot be sent through Javascript to the WCMPojo, because the javascript section loads after the HTML/JSP has been loaded. So, even if you fetch the cookie value using Javascript it will never reach the WCMPojo class until you reload via some dynamic template binding.
The other options are:-
1. Directly fetch the cookie in WCMPojo class using the request object
Cookie[] cookies = request.getCookies();
for (Cookie cookie: cookies) {
String value = cookie.getValue();
}
2. Use the 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>