# Using images field plugin within a structure

**URL:** <https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 9, 2018, 11:52am UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929 "2018-03-09T11:52:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![firstklaas](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@firstklaas](https://forum.getkirby.com/u/firstklaas)\
**Post date:** [March 9, 2018, 11:52am UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929/1 "2018-03-09T11:52:32Z")

</div>

I’m using a structure field to build a timeline on my website. I would need to show multiple images (with a slider) for each event of the timeline. This is my code so far for a single image for each event:

```
<?php
	$events = $page->events()->yaml();
    foreach($events as $event): ?>	
	  <dl>                                  
	    <dd class="pos-<?php echo $event['positie'] ?> clearfix">
	      	<div class="circ"></div>
	      	<div class="time">
	      	<?php $somedate = $event['event_datum']; echo date('M Y', strtotime($somedate)) ?>	
	      	</div>
	      	<div class="events">
	        	<div class="events-header"><?php echo $event['event_titel'] ?></div>                                
	        	<div class="events-body">                                                                                            
					<?php if($image = $page->image($event['event_beeld'])) echo thumb($image, array('width' => 200, 'height' => 150, 'crop' => true)); ?>
					<div class="events-desc">
					<?php echo $event['event_tekst'] ?>
					</div>
	          </div>                                 
	      	</div>
	    </dd>		   
	  </dl>
	<?php endforeach ?>

```

My blueprint:

```
 fields:
  event_datum:
    label: Datum
    type: date
  event_titel:
    label: Titel
    type: text
  event_tekst:
    label: Tekst
    type: textarea
  event_beeld:
    label: Afbeelding
    type: image

```

I would like to use the ‘images’ field of this plugin: [GitHub - medienbaecker/kirby-images](https://github.com/medienbaecker/kirby-images)

Is this possible and could you help me on my way to accomplish this? Thank you for your help.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 9, 2018, 12:03pm UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929/2 "2018-03-09T12:03:07Z")

</div>

Yes, it’s possible. When you fetch the images field, you have to use the structure() or yaml() method again to get the images collection, then loop through that collection. I’d use `toStructure()` for both, then you can use chaining syntax.

```auto
<?php
$imageNames = $event->event_beeld()->structure();
foreach($imageNames as $imageName):
  if($image = $imageName->toFile()):
    echo $image;
  endif;
endforeach;
?>

```

Note: You can’t drag and drop images into the field when using the images field within a structure field, but it works using the add button.

---

<div class="post-metadata">

**Author:** ![firstklaas](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@firstklaas](https://forum.getkirby.com/u/firstklaas)\
**Post date:** [March 10, 2018, 1:37pm UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929/3 "2018-03-10T13:37:20Z")

</div>

Thank you very much for your fast answer. However, i’m getting the error ‘Call to a member function event\_beeld() on array’

Any idea why and how i can solve this?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 10, 2018, 2:48pm UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929/4 "2018-03-10T14:48:31Z")

</div>

That’s probably because you are using `yaml()` in your first loop. You’d better change that `structure()`.

```auto
$events = $page->events()->structure();
foreach($events as $event): ?>	
<dl>                                  
  <dd class="pos-<?= $event->positie() ?> clearfix">
    <div class="circ"></div>
    <div class="time">
      <?php 
      $somedate = $event->event_datum(); 
      echo date('M Y', strtotime($somedate));
      ?>	
    </div>
    <div class="events">
      <div class="events-header"><?= $event->event_titel() ?></div>                                
      <div class="events-body">   
        <?php
        $imageNames = $event->event_beeld()->structure();
        foreach($imageNames as $imageName):
          if($image = $imageName->toFile()):
            echo thumb($image, array('width' => 200, 'height' => 150, 'crop' => true));
          endif;
        endforeach;
        ?>                         
        <div class="events-desc">
          <?= $event->event_tekst() ?>
        </div>
      </div>                                 
    </div>
  </dd>		   
</dl>
<?php endforeach ?>

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/using-images-field-plugin-within-a-structure/9929/5 "2025-02-06T17:28:39Z")

</div>


