# Selecting images from another page

**URL:** <https://forum.getkirby.com/t/selecting-images-from-another-page/25935>\
**Category:** Questions\
**Tags:** v3\
**Created:** [July 7, 2022, 9:53am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935 "2022-07-07T09:53:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![darkflare](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/darkflare/32/12091_2.png) [@darkflare](https://forum.getkirby.com/u/darkflare)\
**Post date:** [July 7, 2022, 9:53am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/1 "2022-07-07T09:53:23Z")

</div>

Hi, I’m wondering if it’s possible to select images from another page?

I have Starterkit installed, which I’ve added a Gallery page to. Ideally I’d like to be able to populate the Photography \> Album pages by selecting images from the Gallery page.

From having a browse on the forum, and looking at the documentation it seems I may be able to do this using a query in the blueprint. However, nothing I’ve tried seems to work.

My gallery.yml Blueprint:

```auto
title: Gallery

sections:
  files:
    label: Gallery images
    type: files
    layout: cards
    size: medium
    template: gallery-image
    text: "{{ file.title }}"
    info: "{{ file.photographer }}"
    image:
      cover: true

```

…and my album.yml Blueprint:

```auto
title: Album

icon: 🖼

status:
  draft: true
  listed: true

columns:
  - width: 1/3
    fields:
      cover: fields/cover
      headline:
        type: text
        placeholder: "{{ page.title }}"
        help: Leave empty to use the title as headline
      subheadline:
        type: text
      text:
        type: writer
      tags: true

  - width: 2/3
    sections:
      images:
        type: files
        layout: cards
        size: medium
        template: gallery-image
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true
        options: query
        query: site.find('gallery').images
        uploads: 
            parent: site.find('gallery')
            template: gallery-image

```

I’ve also tried using:

```auto
query: site.find('gallery').images.template('gallery-image')

```

When editing an album page I still get the Add Files option, not the Add \> Select or Upload like the Cover image.

 ![Capture](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/0/022cb42677b6095076b06f55d1d6f07818554386.jpeg)

When I do upload an image it still uploads to that particular album’s folder and not the gallery content folder.

Is it possible to do what I’ve described?

I’ve only recently started using Kirby, so I feel like I could be missing something obvious here.

Any help would be much appreciated.

Thanks,  
Iain

---

<div class="post-metadata">

**Author:** ![darkflare](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/darkflare/32/12091_2.png) [@darkflare](https://forum.getkirby.com/u/darkflare)\
**Post date:** [July 7, 2022, 10:45am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/2 "2022-07-07T10:45:31Z")

</div>

Update: I’ve also tried using a page model for this.

site/models/album.php:

```auto
class AlbumPage extends Page
{
    public function cover()
    {
        return $this->content()->get('cover')->toFile() ?? $this->image();
    }
	
	public function getAllImages()
	{
		return $this->images()->add($site->find('gallery')->images());
	}
}

```

album.yml Blueprint:

```auto
title: Album

icon: 🖼

status:
  draft: true
  listed: true

columns:
  - width: 1/3
    fields:
      cover: fields/cover
      headline:
        type: text
        placeholder: "{{ page.title }}"
        help: Leave empty to use the title as headline
      subheadline:
        type: text
      text:
        type: writer
      tags: true

  - width: 2/3
    sections:
      images:
        type: files
        layout: cards
        size: medium
        template: gallery-image
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true
        options: query
        query: page.getAllImages
        uploads: 
            parent: site.find('gallery')
            template: gallery-image

```

No luck with this either unfortunately. 😭

Also, forgot to say I’m using Kirby 3.7.0.2 running on PHP 8.1.6

---

<div class="post-metadata">

**Author:** ![tojai](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tojai/32/12075_2.png) [@tojai](https://forum.getkirby.com/u/tojai)\
**Post date:** [July 7, 2022, 10:54am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/3 "2022-07-07T10:54:43Z")

</div>

When you look closely at [Files section | Kirby CMS](https://getkirby.com/docs/reference/panel/sections/files#section-properties) you’ll find the parameters `parent` and `uploads`.

```auto
parent: site
query: site.images
uploads:
  parent: site
  template: image

```

This will find you all images below site and upload them to the same directory.

---

<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:** [July 7, 2022, 11:11am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/4 "2022-07-07T11:11:54Z")

</div>

A files section does not have query option. You have to set the parent property:

```auto
sections:
  images:
    type: files
    parent: site.find('gallery')
    template: gallery-image

```

`query` and `uploads` are properties of the files **field**.

---

<div class="post-metadata">

**Author:** ![darkflare](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/darkflare/32/12091_2.png) [@darkflare](https://forum.getkirby.com/u/darkflare)\
**Post date:** [July 7, 2022, 11:25am UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/5 "2022-07-07T11:25:01Z")

</div>

@texnixe Thanks Sonja.

I’ve updated my album.yml to contain:

```auto
    sections:
      images:
        label: Images
        type: files
        parent: site.find('gallery')
        template: gallery-image
        layout: cards
        size: medium
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true

```

All of my Album pages (in the Panel) now display all of the images in Gallery, and upload to Gallery.

Is it possible to select which images from Gallery appear in each Album?

---

<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:** [July 7, 2022, 12:00pm UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/6 "2022-07-07T12:00:11Z")

</div>

No, a section is not for selecting files, if you want to select files out of a set, you would need a **files field** instead.

---

<div class="post-metadata">

**Author:** ![darkflare](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/darkflare/32/12091_2.png) [@darkflare](https://forum.getkirby.com/u/darkflare)\
**Post date:** [July 7, 2022, 12:38pm UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/7 "2022-07-07T12:38:17Z")

</div>

Thank you! I’ve updated my original album.yml above, swapping section: for fields: and it’s now working as expected!

```auto
    fields:
      images:
        type: files
        layout: cards
        size: medium
        template: gallery-image
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true
        options: query
        query: site.find('gallery').images
        uploads: 
            parent: site.find('gallery')
            template: gallery-image

```

Now I just need to work out how to get them to display on the front-end.

---

<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:** [July 7, 2022, 12:50pm UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/8 "2022-07-07T12:50:10Z")

</div>

> **[Files](https://getkirby.com/docs/reference/panel/fields/files#how-to-use-in-templates-snippets)**
>
> A files select field that allows to select one or multiple related files

---

<div class="post-metadata">

**Author:** ![darkflare](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/darkflare/32/12091_2.png) [@darkflare](https://forum.getkirby.com/u/darkflare)\
**Post date:** [July 7, 2022, 1:11pm UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/9 "2022-07-07T13:11:31Z")

</div>

Thanks, I was already looking at that, and seem to have sussed it out.

Not sure if this will help anyone else in the future, but I’ve updated the file controllers/album.php to the below, and all seems to be working as expected.

```auto
return function ($page) {

    $gallery = $page->content()->get('images')->toFiles()->sortBy('sort', 'filename');

    return [
        'gallery' => $gallery
    ];

};

```

For completeness, this is the corresponding field from the album.yml blueprint:

```auto
    fields:
      images:
        type: files
        layout: cards
        size: medium
        template: gallery-image
        info: "{{ file.dimensions }}"
        image:
          ratio: 5/4
          cover: true
        options: query
        query: site.find('gallery').images
        uploads: 
            parent: site.find('gallery')
            template: gallery-image

```

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![tojai](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/tojai/32/12075_2.png) [@tojai](https://forum.getkirby.com/u/tojai)\
**Post date:** [July 7, 2022, 5:10pm UTC](https://forum.getkirby.com/t/selecting-images-from-another-page/25935/10 "2022-07-07T17:10:14Z")

</div>

my bad! thx for watching out @texnixe !
