Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error symfony Key "" for array with keys "…" does not exist

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to make a loop of this include but that didn’t work.

>Solution :

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 %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading