# K3 Page Builder: accessing files for a gallery

**URL:** <https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 11, 2019, 9:31am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806 "2019-02-11T09:31:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![9zehn81](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/9zehn81/32/735_2.png) [@9zehn81](https://forum.getkirby.com/u/9zehn81)\
**Post date:** [February 11, 2019, 9:31am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/1 "2019-02-11T09:31:46Z")

</div>

@timoetting s K3 Page Builder is fantastic! I’m creating some different Block-Types, e.g. an image gallery.

But i can’t manage to display all selected files (images) with accessing them as files (in order to use the alt and caption text from the file).

The only way i could display the images yet is:

```
<?php foreach($data->bilder()->yaml() as $bild): ?>
<div>
      <?php if($full = $bild['url']): ?>
      <a class="uk-inline" href="<?php echo $full ?>" alt="Alt" data-caption="Caption 1">
        <img src="<?php echo $full ?>">
      </a>
      <?php endif ?>
</div>
<?php endforeach ?>  

```

But this way i cant access the files-meta infos and i cannot even crop them 😕

---

<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:** [February 11, 2019, 9:43am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/2 "2019-02-11T09:43:52Z")

</div>

> [@9zehn81](#):
>
> \<?php foreach($data-\>bilder()-\>yaml() as $bild): ?\>

`$data->bilder()->toFiles()` doesn’t work?

If not, please provide your blueprint.

---

<div class="post-metadata">

**Author:** ![9zehn81](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/9zehn81/32/735_2.png) [@9zehn81](https://forum.getkirby.com/u/9zehn81)\
**Post date:** [February 11, 2019, 9:49am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/3 "2019-02-11T09:49:51Z")

</div>

No, -\>toFile() doesn’t work

The blueprint is:

```
label: Inhaltsblöcke
type: builder
columns: 1
max: 10
fieldsets:
  bodytext:
    label: Textblock
    tabs:
      content:
        label: Bearbeiten
        icon: edit
        fields:
          text:
            label: Text
            type: textarea
  bildergalerie:
    label: Bildergalerie
    tabs:
      content:
        label: Bearbeiten
        icon: edit
        type: fields
        fields:
          bilder:
            label: Bilder
            type: files
      einstellungen:
        label: Einstellungen
        icon: cog
        fields:
          spalten:
            label: Spalten
            type: select
            options:
              drei: 3-spaltig
              vier: 4-spaltig
              fuenf: 5-spaltig
```

---

<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:** [February 11, 2019, 10:40am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/4 "2019-02-11T10:40:43Z")

</div>

Hm, ok, this seems to work:

```auto
<?php 
foreach($data->bilder() as $bild) {
    if($img = $page->image($bild['filename'])) {
        dump($img);
    }
}
?>

```

Don’t know if this is the best way…

---

<div class="post-metadata">

**Author:** ![9zehn81](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/9zehn81/32/735_2.png) [@9zehn81](https://forum.getkirby.com/u/9zehn81)\
**Post date:** [February 11, 2019, 11:05am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/5 "2019-02-11T11:05:40Z")

</div>

i tried your snippet right now, but it causes the error “Undefined index: filename”

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [February 11, 2019, 12:04pm UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/6 "2019-02-11T12:04:17Z")

</div>

I figured this out yesterday. `->tofiles()` does work. Something doesn’t feel right about your blueprint. I would double check the structure, the german is confusing me 🙂

```auto
<?php 
$gallery = $data->bilder()->toFiles();

foreach($gallery as $bild): ?>
  // Remember to check the image exists...
  <img src="<?= $bild->url() ?>">
<?php endforeach ?>  

```

> [@9zehn81](#):
>
> i tried your snippet right now, but it causes the error “Undefined index: filename”

You have probably taken `->yaml()` out an swapped it for `->toFiles()`.

---

<div class="post-metadata">

**Author:** ![timoetting](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timoetting/32/781_2.png) [@timoetting](https://forum.getkirby.com/u/timoetting)\
**Post date:** [February 11, 2019, 1:57pm UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/7 "2019-02-11T13:57:48Z")

</div>

Hey.

I just pushed a new version that fixes some issues with tabs and the files field. It should now work exactly like accesing images from within a structure field

To access images of a builder fieldset you can use something like this:

```auto
<?php foreach($data->images()->toFiles() as $image): ?>
    <?= $image->resize(100) ?>
<?php endforeach ?>

```

In the old version, this did only work when not having tabs in the fieldset.

---

<div class="post-metadata">

**Author:** ![9zehn81](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/9zehn81/32/735_2.png) [@9zehn81](https://forum.getkirby.com/u/9zehn81)\
**Post date:** [February 12, 2019, 6:08am UTC](https://forum.getkirby.com/t/k3-page-builder-accessing-files-for-a-gallery/12806/8 "2019-02-12T06:08:25Z")

</div>

Yes, great, with the latest update it all works fine! Thank you so much.
