1

I'm building a content website in Craft CMS. I use single entries to output images, but after I updated Craft to 3.2.1, this doesn't work. Everything else is working fine.

I get this error: Twig Runtime Error – Twig\Error\RuntimeError Key "1" in object with ArrayAccess of class "craft\elements\db\AssetQuery" does not exist.

    <div class="detail_content_photos3 row">
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
            <img src="{{ entry.videoPhoto3x3[0].url }}"/>
        </div>
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
            <img src="{{ entry.videoPhoto3x3[1].url }}"/>
        </div>
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
            <img src="{{ entry.videoPhoto3x3[2].url }}"/>
        </div>
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
            <img src="{{ entry.videoPhoto3x3[3].url }}"/>
        </div>
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
            <img src="{{ entry.videoPhoto3x3[4].url }}"/>
        </div>
        <div class="detail_content_photos3_photo col-xs-12 col-md-4">
        <img src="{{ entry.videoPhoto3x3[5].url }}"/>
        </div>
    </div>

1 Answers1

0

This is happening because the entry does not have 6 images assigned to that field, only 1, which is key zero. When twig tries to access the non-existant 2nd image, it throws the runtime error. If you are wanting to display all the images, you can do something like:

<div class="detail_content_photos3 row">
  {% for image in entry.videoPhoto3x3.all() %}
    <div class="detail_content_photos3_photo col-xs-12 col-md-4">
      <img src="{{ image.url }}"/>
    </div>
  {% endfor %}
</div>

The {% for image ... %} lets you access each asset without needing to know its index, or how many there are etc.

Jonathan Bennett
  • 1,055
  • 7
  • 14