5

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... :/

Markus Kottländer
  • 8,228
  • 4
  • 37
  • 61

1 Answers1

2

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 %}
bsnrijal
  • 494
  • 4
  • 7
  • Thank you for your suggestions but unfortunatly the problem seems to be something else. I have another array with the exact same structure and everythin behaves as expected. The only difference between them is how they are build in PHP. But the resulting structure ist the same as I mentioned before. I am absolutly puzzled... :D – Markus Kottländer Nov 26 '13 at 08:35
  • 1
    Ok this works: `{{ image.datei|default('') }}` This looks like some elements just have no property called 'datei' but my array only has to elements and both have a value for this property and both are printed now... – Markus Kottländer Nov 26 '13 at 09:08