<p>For now, you have to use a plugin</p>

<p>I recommend one of these 2</p>

<ol>
<li>Craft Cookies Plugin <a href="https://github.com/nystudio107/craft-cookies" rel="nofollow noreferrer">https://github.com/nystudio107/craft-cookies</a></li>
<li>Craft LJ Cookies Plugin <a href="https://github.com/khamer/craft-lj-cookies" rel="nofollow noreferrer">https://github.com/khamer/craft-lj-cookies</a></li>
</ol>

CC BY-SA 4.0
2020-03-28T05:17:24.973Z
2020-03-28T05:17:24.973Z
Tunji Oyeniran
<p>So far the only solution I have found is to use a plugin, and Lewis Jenkins' <a href="https://github.com/khamer/craft-lj-cookies" rel="nofollow noreferrer">LJ Cookies plugin</a> does the trick nicely:</p>

<pre><code>{{ craft.lj_cookies.get( NAME ) }}
</code></pre>

<p>It also allows you to set and delete cookies within templates.</p>

CC BY-SA 3.0
2017-05-02T22:05:22.150Z
It really bugs me that I have to have a whole plugin just to access a cookie set from JS. That's a very "Wordpress" solution to a problem. The Craft guys need to figure out a correct way to do this. Given how ajax heavy most sites are it's a super common way to set cookies. Not much good if you can't get the values back.
JamesNZ
CC BY-SA 4.0
2020-03-28T05:15:12.500Z
Please update the LJ Cookies Plugin Github Repo to https://github.com/khamer/craft-lj-cookies
Tunji Oyeniran
CC BY-SA 4.0
2020-03-28T18:12:46.600Z
Updated, thanks!
Ben Croker
CC BY-SA 4.0
2014-09-15T12:16:29.800Z
2020-03-28T18:12:33.823Z
2020-03-28T18:12:33.823Z
Ben Croker
<p>The <a href="https://docs.craftcms.com/v2/templating/craft.request.html#getcookie-name" rel="nofollow noreferrer">docs</a> state that <code>{{ craft.request.getCookie(name) }}</code> will not work for cookies that were set in JavaScript, because all cookies in Craft go through some validation to ensure that they aren't tampered with. </p>

<p>This is understandable, but is there any way of getting non-Craft cookies with twig?</p>

<templating><cookies><javascript>
How can I get cookies that were set in javascript from a twig template?
# How can I get cookies that were set in javascript from a twig template?

(Asked by: username_0 on 2014-09-15)

The [docs](https://docs.craftcms.com/v2/templating/craft.request.html#getcookie-name) state that `{{ craft.request.getCookie(name) }}` will not work for cookies that were set in JavaScript, because all cookies in Craft go through some validation to ensure that they aren't tampered with.

This is understandable, but is there any way of getting non-Craft cookies with twig?

**Tags:** templating, cookies, javascript


---

## 2 answers

### Answer by username_0 on 2014-09-15. Score: 7 | Accepted answer

So far the only solution I have found is to use a plugin, and Lewis Jenkins' LJ Cookies plugin does the trick nicely:
{{ craft.lj_cookies.get( NAME ) }}

It also allows you to set and delete cookies within templates.

> **Comments:**
> **username_2**: It really bugs me that I have to have a whole plugin just to access a cookie set from JS. That's a very "Wordpress" solution to a problem. The Craft guys need to figure out a correct way to do this. Given how ajax heavy most sites are it's a super common way to set cookies. Not much good if you can't get the values back.  
> **username_1**: Please update the LJ Cookies Plugin Github Repo to https://github.com/khamer/craft-lj-cookies  
> **username_0**: Updated, thanks!  

---

### Answer by username_1 on 2020-03-28. Score: 1

For now, you have to use a plugin

I recommend one of these 2

1. Craft Cookies Plugin <https://github.com/nystudio107/craft-cookies>
2. Craft LJ Cookies Plugin <https://github.com/khamer/craft-lj-cookies>


---

