Jump to main content Jump to doc navigation

What is cookieJar?

This extra includes a set of MODX Revolution snippets for setting, retrieving and deleting browser Cookies.

History

cookieJar was first written by David Pede and last released on December 13, 2018.

Download

It can be downloaded from within the MODX Revolution manager via Package Management, or from the MODX Extras Repository, here: https://modx.com/extras/package/cookiejar

The source code and build script is also available on GitHub: https://github.com/tasianmedia/cookiejar

Bugs & Feature Requests

Bugs, issues and feature requests can be reported in the GitHub Repository, found here: https://github.com/tasianmedia/cookiejar/issues

Available Snippets

setCookie

The setCookie snippet can be called using the tag:

[[seCookie]]

setCookie can be called cached or un-cached.

getCookie

The getCookie snippet can be called using the tag:

[[!getCookie]]

Available Properties

setCookie

Name Description Default Value Added in Version
name The name of the cookie. [REQUIRED] 1.0.0-pl
value The value of the cookie. This value is stored on the clients computer, do not store sensitive information. 1.0.0-pl
expires The time the cookie expires. This is a Unix timestamp so is in number of seconds. Use 0 to set a session cookie. Use any date in the past to delete a cookie. 0 1.0.0-pl
expiresType The period unit for the cookie expires. Valid inputs are: 'years', 'months', 'days', 'weeks', 'hours', 'minutes' and 'seconds'. seconds 1.1.0-pl
path The path on the server in which the cookie will be available on. Use / to make available within the entire domain. / 1.0.0-pl
domain The domain that the cookie is available to. 1.0.0-pl
secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. 0 1.0.0-pl
httponly Indicates that the cookie will be made accessible only through the HTTP protocol. This means that the cookie wont be accessible by scripting languages, such as JavaScript. 0 1.0.0-pl

getCookie

Name Description Default Value Added in Version
name The name of the cookie to be returned. [REQUIRED] 1.0.0-pl
tpl Name of a chunk serving as a template. 1.0.0-pl
toPlaceholder If set, will assign the output to this placeholder instead of outputting it directly. value 1.0.0-pl

Examples

setCookie

Set a Session Cookie:

[[!setCookie?
    &name=`foo`
    &value=`foobar`
    &expires=`0`
]]

Set a secure Cookie that expires in one hour:

[[!setCookie?
    &name=`foo`
    &value=`foobar`
    &expires=`1`
    &expiresType=`hours`
    &secure=`1`
]]
//or using seconds
[[!setCookie?
    &name=`foo`
    &value=`foobar`
    &expires=`3600`
    &secure=`1`
]]

Set a secure Cookie that expires in one day:

[[!setCookie?
    &name=`foo`
    &value=`foobar`
    &expires=`1`
    &expiresType=`days`
    &secure=`1`
]]

Delete a Cookie named 'foo':

[[!setCookie?
    &name=`foo`
    &expires=`-3600`
]]

getCookie

Output the value of a Cookie named 'foo':

[[!getCookie?
    &name=`foo`
]]

Output the value of a Cookie named 'foo', using a 'cookieTpl' chunk and assign the value to a placeholder:

[[!getCookie?
    &name=`foo`
    &tpl=`cookieTpl`
    &toPlaceholder=`cookieValue`
]]

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more