Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple plugin for setting and retrieving cookies from within Craft CMS templates
PHP
branch: master
Failed to load latest commit information.
lj_cookies Initial commit
README.md Update README.md

README.md

LJ Cookies plugin for Craft CMS

A simple plugin for setting and retrieving cookies from within Craft CMS templates.

Installation

  1. Unzip file
  2. Place lj_cookies directory into your craft/plugins directory
  3. Install plugin in the Craft Control Panel under Settings > Plugins

Setting cookies

{% do craft.lj_cookies.set( NAME, VALUE, EXPIRE, PATH, DOMAIN, SECURE, HTTPONLY) %}

This plugin acts as a wrapper for the PHP setcookie function:

More info: (http://php.net/manual/en/function.setcookie.php)

Examples

{% do craft.lj_cookies.set('myname', 'myvalue') %}
{# Sets a cookie to expire at end of session. #}

{% do craft.lj_cookies.set('myname', 'myvalue', now | date_modify("+1 hour").timestamp ) %}
{# Sets a cookie to expire in an hour. #}

{% do craft.lj_cookies.set('myname', 'myvalue', now | date_modify("+30 days").timestamp ) %}
{# Sets a cookie to expire in 30 days. #}

{% do craft.lj_cookies.set('myname', 'myvalue', '', '/' ) %}
{# Cookie available for entire domain. #}

{% do craft.lj_cookies.set('myname', 'myvalue', '', '/foo/' ) %}
{# Cookie available within /foo/ directory and sub-directories. #}

Retrieving cookies

{{ craft.lj_cookies.get( NAME ) }}
{# Note that we're using 'get' to retrieve. #}

Example

{% do craft.lj_cookies.set('user', 'Lewis', '', '/') %}
{# Set the cookie using 'set' #}

<p>Howdy, {{ craft.lj_cookies.get('user') }}</p>
{# Retrieve the cookie's value using 'get' #}

Deleting cookies

{% do craft.lj_cookies.set('myname', '') %}
{# Delete a cookie by setting an empty value #}

Tested on

  • Craft 2.0 and below
Something went wrong with that request. Please try again.