Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Retrieve cookie using get_cookie()

Started by Muut Archive 10 years ago · 9 replies · 1422 views
10 years ago

Hi, I'm trying to retrieve a cookie using this Grav Method: https://learn.getgrav.org/themes/twig-filters-functions#get-cookie

I tried:
{% set foo = get_cookie('MY_COOKIE') %}
<p>var: {{foo}}</p>

But it's not working. Is this function retrieve a cookie from the header response of the page or a cookie previously set by the front-end (JS) for example?

Basically I need to read some cookies from a response header OR to read headers directly, is there a way to accomplish that?

Thanks

10 years ago

The cookie is set but I think the get_cookie() method isn't working as using dump()always returns null, even if the cookie is set.

10 years ago

As written in Twitter, to me it works, with a simple numeric cookie. Could it be that the implementation of get_cookie as linked above is filtering it? Post more information, what's the content of the cookie, how are you calling it in your twig?

10 years ago

P.S. Grav 1.1 has solved many issues and it's nearly ready to be released so please use that.

10 years ago

@flaviocopes7d works perfectly in Grav 1.1, thanks

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1369 9 years ago
Archive · by Muut Archive, 9 years ago
2 942 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago