Get cookie from Twig template Get cookie from Twig template symfony symfony

Get cookie from Twig template


Twig has the global app helper context, via which you can access the cookies (among other things). Try this:

{{ dump(app.request.cookies) }}

And ultimately:

{{ app.request.cookies.get('MY_COOKIE_NAME') }}

Remember, cookies is an instance of ParameterBag (API), so you have to access it via get() call.

Hope this helps...


Past Cookie variable from the controller and check it. It works to me.My code in controller is:

$data['cookie'] = $_COOKIE['postcode'];

postcode is my cookie name and in my twig templete, i write this line of code

{{  cookie  }}

and show my cookie value. Thanks.