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 class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>


<?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:


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

The blueprint looks like this:

    label: Show and Tell
    type: builder
        label: Single Image
        snippet: builder/singleimage
            label: Image
            type: image
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
        label: Slideshow
        snippet: builder/slideshow
            label: Slides
            type: gallery
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
        label: Video
        snippet: builder/video
            label: Video URL (Vimeo or Youtube)
            type: text
            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?


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:


  slide: >
  slide: table.jpg

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

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

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


but does not work properly in a nested field.