CookieTool Viewtool

Last Updated: Jan 6, 2023
documentation for the dotCMS Content Management System

The Cookietool Velocity Viewtool allows you to create and access cookies. This class is only designed for use as a request-scope tool. It exposes the methods of the standard CookieTool viewtool.

Note: This viewtool cannot be used directly from a static page — e.g., one served via CDN — but can still be utilized through the Scripting API in such a case.

The following snippet shows how the CookieTool Viewtool is mapped in the toolbox.xml file:



$ or $cookietool.get("foo")Retrieves the cookie with the Name attribute of foo
$ the Value of the specified cookie
$ the Name of the specified cookie ("foo", in this case)
$cookietool.add("bar", "woogie"[, 60])Adds a cookie with Name bar, Value woogie, and (optional) MaxAge of 60 seconds
$cookietool.delete("bar")Sets the MaxAge of cookie bar to 0, causing its deletion
$cookietool.allReturns an iterable object of all cookies accessible through the Request object


The following code prints a bulleted list of all cookies associated with the current Request object.

#foreach( $cookie in $cookietool.all )
    <li>${} = ${cookie.value}</li>

On this page


We Dig Feedback

Selected excerpt: