Access Cookies with Tokens in Drupal 7
The Token module supports $_GET, so that [current-page:query:?] returns the query string value of a given parameter. The module doesn't support $_COOKIE, however. There are valid security concerns for not supporting $_COOKIE, but what if you want access cookies through tokens anyway?
Create a Custom Cookie
In this example, we'll create a custom module called 'token_cookie'.
The first step is use hook_token_info() to declare the token:
The next step is to use hook_tokens() to process the tokens:
Now, if you use [current_page:cookie:example-cookie], the rendered markup will be the value of a cookie named 'example-cookie'.
Note: In Drupal 8, you'll still use hook_token_info() and hook_tokens(). The code above might need to be tweaked some, however.
Add new comment