Create a cookie

To create a cookie with the variable name awesomeCookieName and with a value of "James is awesome" use the code below:

You must remember to add an expiry date/length to the cookie. The example below uses 360 days. If you do not set a time, the cookie won't actually store the data past the session (you may wish to use this feature).

  1. $cookietool.add("awesomeCookieName","James is awesome",360)  

You can add a cookie to the header of the page (but just one cookie addition per .vtl) using the following method. By using this method you can set a more explicit expiry date and you can also set the path of the cookie. If you need to store values with single quotes, special characters, including semi-colons etc then you will need to place the value inside quotes. You will need to use the following escape: ${esc.q}$value${esc.q}

  1. $response.setHeader("Set-Cookie","showContentCookie=$showContent;expires=Sat, 01-Jan-2093 00:00:00 GMT;path=/")  
comments powered by Disqus