How to use it
- Select the element and open its Conditions.
- Add the condition Cookie from the Kiln group.
- Choose how to compare: ==, !=, contains, does not contain, exists or does not exist.
- In the value field, type the cookie as
name=value, or onlyname.
Examples:
cookie_consent=yeswith ==: the element shows when the cookiecookie_consentequalsyes.returning_visitorwith exists: the element shows when that cookie is present.cookie_consentalone with !=: the element shows when the cookie is absent.
The name and the value accept dynamic data. Kiln renders it before it splits the text at the first =.
How it works with page caches
A cookie differs for every visitor, so a page that checks one cannot come from a shared cache. When the page
evaluates a Cookie condition, Kiln tells page-cache plugins not to cache it (the DONOTCACHEPAGE constant, the
LiteSpeed Cache no-cache call, and no-cache headers when they have not been sent yet).
A cache at the host or CDN level, such as nginx, Varnish or Cloudflare "cache everything", only sees the response headers. Those are usually sent before Bricks renders the page. Exclude the page from that cache, or make the cache vary by the cookie, or one visitor's version reaches everyone.
Limits
- Matching is exact and case-sensitive. Kiln compares the raw cookie value.
- With no value, == and contains mean the cookie exists. != and does not contain mean it does not.
- With exists or does not exist, Kiln ignores any value.
- An empty cookie name makes the condition false.
- Kiln reads the cookies the browser sent with the request. A cookie your script sets in the browser shows up from the next page load.
Settings
None. Turn the module on in Bricks > Kiln (it is on by default).
Requirements
Bricks 2.4 or newer.