Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key "path" for array with keys "" does not exist while dump says it does

I'm currently working on a cms using symfony2 as the underlying framework and twig as the template engine.

My problem is the following:

While this

{% for image in images %}
    {{ dump(image.path is defined) }}
{% endfor %}

returns true for each element in the array,...

...but this one

{% for image in images %}
    {{ image.path}}
{% endfor %}

throws an exeption.

Key "path" for array with keys "" does not exist

A twig-dump of the images-array returns this:

array(2) {
    [0]=> object(stdClass)#2759 (9) {
        ["id"]=> string(5) "17795"
        ["typ"]=> string(3) "jpg"
        ["path"]=> string(10) "Tulips.jpg"
    }
    [1]=> object(stdClass)#2874 (9) {
        ["id"]=> string(5) "17796"
        ["typ"]=> string(3) "jpg"
        ["path"]=> string(14) "Hydrangeas.jpg"
    }
}

This seems to be paradox to me and i really don't understand this. Has someone an Idea? I would be very thankful, deadlines are coming... :/

like image 880
Markus Kottländer Avatar asked Nov 01 '22 10:11

Markus Kottländer


1 Answers

I think u created multidimensional array. Try foreach loop in twig template for image also

{% for image in images %}
    {% for i in image %}
       {{ i.datei }}
    {% endfor %}
{% endfor %}
like image 148
bsnrijal Avatar answered Nov 08 '22 04:11

bsnrijal