Kirby Builder Image Issue

Im struggling to get data out of Kirby Builder. I have set the Gallery plugin up inside a Builder field, but when i trying and get the data out of the gallery field, its not returning what i need.

I have this in a builder snippet. The gallery field is called slide:

<?php if ($data->slide()->isNotEmpty()): ?>

  <section class="swiper-container slideshow">
    <div class="swiper-wrapper">

      <?php foreach($data->slide()->toStructure() as $image): ?>
      <?php $imageitem = $image->toFile();?>
      <div class="swiper-slide"><?= $imageitem ?></div>
      <?php endforeach ?>

    </div>

    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>

  </section>

<?php endif ?>

The problem is, the <?= $imageitem ?> gives me a full image tag. All i want is the URL and to be able to access things like the image width and the images meta data so i pull it alt tag from the images meta file. If try and do <?= $imageitem->url() ?>. I have also tried using yaml instead of toStructure (i know toStructure is better) and got the same result. A stab in the dark really.

The content looks like this:

Builder: 

- 
  slide: |
    - kioski-thinking-particles-explsn01.jpg
    - kioski-thinking-particles-explsn02.jpg
    - kioski-thinking-particles-explsn03.jpg
    - >
    kioski-thinking-particles-explsn04_tp.png
  toggle: 'true'
  _fieldset: slideshow

The blueprint looks like this:

builder:
    label: Show and Tell
    type: builder
    fieldsets:
      singleImage:
        label: Single Image
        snippet: builder/singleimage
        fields:
          picture:
            label: Image
            type: image
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
      slideshow:
        label: Slideshow
        snippet: builder/slideshow
        fields:
          slide:
            label: Slides
            type: gallery
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
      video:
        label: Video
        snippet: builder/video
        fields:
          vid:
            label: Video URL (Vimeo or Youtube)
            type: text
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3

How can i get all the images data, including meta data?

Thanks

Ah ha! Looks like Gallery or builder saved the data incorrectly to the content file. removing -> fixed it. I donโ€™t know if this is a bug or not, or which plugin the bug could be in.

Make sure that you check if your $imageitem variable is an image object before calling the URL method on it; otherwise, you will get an error in case the image doesnโ€™t exist.

if($imageitem) echo $imageitem->url();

i am facing nearly the same issue. help will be much appreciated.

Thanks for the hint.

I figured out the cause of the error and why the content was being saved badly. Either Kirby, the Gallery plugin or the Builder plugin does not like characters after a number in the filename. I suspect it might be Kirby because it uses numbering on folders to organise content.

Yes, thatโ€™s right, it seems to have to do with the filename, the yaml parser treats entries differently depending on type, which isnโ€™t a problem in a standard structure field:

Img: 

- 
  slide: >
    kioski-thinking-particles_explsn04_tp.jpg
- 
  slide: table.jpg

Result of dump($page->img()->structure():

Array
(
    [0] => Array
        (
            [slide] => kioski-thinking-particles_explsn04_tp.jpg
        )

    [1] => Array
        (
            [slide] => table.jpg
        )

)

but does not work properly in a nested field.