In the HOOK of my project XXX_preprocess I am defining a variable based on a cookie.
My Hook function
function XXXXXX_preprocess(array &$variables) {
if (isset($_COOKIE[personsSearchCookie]) && !empty($_COOKIE[personsSearchCookie])) {
$personsFilter = explode("-", $_COOKIE[personsSearchCookie]);
$variables["personsFilter"] = array (
"filterType" => $personsFilter[0],
"filterId" => $personsFilter[1]
);
}
But in the Twig template, it always gives me the initial value of that variable, it never changes. My Twig code:
Filtering results by [{{ personsFilter.filterType }}]<br />
{% if personsFilter is defined and personsFilter.filterType is defined and personsFilter.filterType is not empty %}
{% if personsFilter.filterType == "area" %}
Filtering by Area <br />
{% endif %}
{% if personsFilter.filterType == "office" %}
Filtering by Office <br />
{% endif %}
{% else %}
No filtering
{% endif %}
This should be a cache theme, right?
How can I make so that when my cookie changes, the variable is modified and since twig can access the new value?
In the prepreocess function in all re-loads, the variable change correctly, but, in twig, the variable have bad value.
Thank you!