{{ cookies }}

The cookies object is available on every page, and contains information regarding the cookies sent with the request. Note that this will typically only include cookies for the current or top-level domain on multi-domain sites.

Properties

string object_type
Will always be "cookies".
true/false is_valid
Will always be true.

Individual cookies on this request may be accessed using {{ cookies.cookieName }} or {{ cookies['cookieName'] }} syntax.

You may also treat this object as a list containing all of the cookies which may be iterated using a {% for %} loop. For more details, see the examples below:

Examples

{% if cookies.customCookieName %}
    {% assign cookieValue = cookies.customCookieName %}
{% elsif cookies['alternate-cookie-name'] %}
    {% assign cookieValue = cookies['alternate-cookie-name'] %}
{% endif %}
{% if cookieValue != empty %}
    <p>Do something with {{ cookieValue }}</p>
{% endif %}

To list all of the cookies in the current request:

<h4>Cookies:</h4>
<ul>
{% for cookie in request.cookies %}
    <li><strong>{{cookie}}</strong> = {{cookies[cookie]}}</li>
{% endfor %}
</ul>

Developer Overview

Liquid Markup