I have an issue with a cookie when in the controller in the same request I don't get it immediately available in the template.
However when I reload it appears.
Controller
$response = $this->render(':frontend/homepage:homepage.html.twig');
$now = new \DateTime();
$response->headers->setCookie
(
new Cookie
(
'affiliateTracker',
serialize
(
array
(
'name' => 'John Doe'
)
),
$now->modify('+24 hours'), '/'
)
);
$response->sendHeaders();
return $response;
Template
{% if app.request.cookies.get('affiliateTracker') %}
<div class="alert text-center alert-success">
<i class="fa fa-user"></i> <strong>Your Name:</strong> {{ app.request.cookies.get('affiliateTracker').name }}
</div>
{% endif %}