I need some help with this error
Key "dateFinValidite" for array with keys "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22" does not exist.
I use this here:
{{ include('/Unite/inc.listUnites.html.twig', {'unites': unites.dateFinValidite|filter(u => u > "now"|date('U'))}) }}
What I want is to show only avalaible date.
I tried to make a loop of this include but that didn't work.
unites
is an array and you are trying to access his dateFinValidite
attribute of it which is, i assume, an attribute of each entry of this array. This is not an error related to symfony or twig.
This is why you get this error.
The proper code would be something like this :
{% for unite in unites %}
{% if unite.dateFinValidite > "now"|date('U') %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite) }}
{% endif %}
{% endfor %}
OR something like this
{% for unite in unites|filter(unite => unite.dateFinValidite > "now"|date('U')) %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite) }}
{% endfor %}