Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8914

Reading cookie in Velocity template

Is it possible to read a cookie value in portal_normal.vm in Liferay 6.2?

Upvotes: 2

Views: 1818

Answers (2)

Arjun Nayak
Arjun Nayak

Reputation: 1260

you can also do it using javaScript in portal_normal.vm

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
}

Goto javaScript cookie

Upvotes: 1

Tobias Liefke
Tobias Liefke

Reputation: 9022

You can use the cookie access method from the request:

#set($previousWeb = "...")
#foreach($cookie in $request.getCookies())
    #if ($cookie.getName() eq "web")
        #set($previousWeb = $cookie.getValue())
    #end
#end

Upvotes: 5

Related Questions