Accessing cookies directly in your Symfony Twig views

In Symfony, cookies are stored in the app.request object. Here’s how you access them in Twig:

{% app.request.cookies %}

To see if a cookie is set, use the if statement inside Twig:

{% if app.request.cookies.has('yourCookie') %}
  Cookie 'yourCookie' has been set.  {{ app.request.cookies.get('yourCookie') }} 
{% endif %}

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *