# Files section / field: multiple parents

**URL:** <https://forum.getkirby.com/t/files-section-field-multiple-parents/13823>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 16, 2019, 12:35pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823 "2019-04-16T12:35:59Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 12:35pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/1 "2019-04-16T12:35:59Z")

</div>

Can you combine query results? For instance: query more than one parent in a files field or section?  
Concrete use case: I need a files field where the user can insert an image from either one of two folders. It would be nice if I could also display all the images from these two folders in a files section.

---

<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:** [April 16, 2019, 1:00pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/2 "2019-04-16T13:00:29Z")

</div>

A files section can only have a single parent. To display files from multiple parents, you would have to create multiple files sections or a custom section.

Querying multiple pages in a files **field** should be possible.

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 1:55pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/3 "2019-04-16T13:55:30Z")

</div>

EDIT: had a mistake in my query

Thanks for the suggestions. Multiple file sections is the workaround I have right now. But I don’t see how I can combine queries in a files field. I tried

```auto
  fields:
    image:
      label: Image
      type: files
      query: page.images.add(site.find("images").images)

```

(And also `extend` instead of `add`)

Note: there is an images folder at site level. Both `page.images` and `site.find("images").images` queries work fine, but I don’t see how I can combine the results.

---

<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:** [April 16, 2019, 2:03pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/4 "2019-04-16T14:03:30Z")

</div>

You could probably use a [files collection](https://getkirby.com/docs/guide/templates/collections)?

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 2:36pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/5 "2019-04-16T14:36:03Z")

</div>

Collections don’t seem to work in queries? Tried:

in `collections/images.php`:

```auto
return function ($site) {
  return $site->find("images")->images();
};

```

and in the files field:  
`query: collection("images")`

but that yields “The files query does not seem to be correct”

---

<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:** [April 16, 2019, 2:43pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/6 "2019-04-16T14:43:16Z")

</div>

Try

```auto
query: kirby.collection("images")

```

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 3:04pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/7 "2019-04-16T15:04:39Z")

</div>

Of course. That works indeed. But now I’m back to square one because the `$page` object is not available in custom collections, nor does `$site->page()` seem to work there. So I’m still not able to collect _site_ files with _page_ files.

Guess I’m asking too much 🙂

---

<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:** [April 16, 2019, 3:11pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/8 "2019-04-16T15:11:15Z")

</div>

But you can combine the collections, for example:

```auto
<?php
return function ($site) {
    $siteImages = $site->images();
    $pageImages = page('photography')->children()->first()->images();
    $allImages = $siteImages->add($pageImages);
  return $allImages;
};

```

You can use the `page()` helper here to get a page by ID, or use `$site->find()` or whatever you need to find the page or pages you want to query for files.

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 3:23pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/9 "2019-04-16T15:23:47Z")

</div>

Yeah, but I’m querying the collection on a files field of a page I’m _creating_.

The catch is: I want query the files from _this page_ (that I’m creating) + some other files I can get via the `$site` object.  
So I can either query the `$page` object directly in the query but then I can’t combine the results with whatever else I want to query (apparently), OR I can use a custom collection and combine stuff there but that collection is agnostic of the page I’m creating so it can’t add that page’s files there either.

---

<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:** [April 16, 2019, 3:57pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/10 "2019-04-16T15:57:00Z")

</div>

```auto
return function ($site) {
    $siteImages = $site->images();
    $pageImages = page()->images();
    $allImages = $siteImages->add($pageImages);
  return $allImages;
};

```

The `page()` helper without a parameter always refers to the current page…

So if you query that collection in Page A, you will get the site’s file + the images uploaded to Page A.

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 16, 2019, 5:36pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/11 "2019-04-16T17:36:45Z")

</div>

I did try the $site-\>page() helper, but the list turns up empty if I do. So I presumed it doesn’t work from a custom collection. Do you think that’s a bug? If so I can file an issue.

---

<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:** [April 16, 2019, 6:26pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/12 "2019-04-16T18:26:29Z")

</div>

Yes, you are right, I tested in the home page and there it works, but not on other pages. So it doesn’t seem to be possible to fetch the current page in a collection, because the page helper in that case always gets the home page, not the current page, too bad. `$site->index()->current()` doesn’t work, either.

The page helper works fine when calling the above collection in any template, but in a Panel context, it stops working and defaults to the home page.

😢

---

<div class="post-metadata">

**Author:** ![phm](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/phm/32/6292_2.png) [@phm](https://forum.getkirby.com/u/phm)\
**Post date:** [April 25, 2019, 2:03pm UTC](https://forum.getkirby.com/t/files-section-field-multiple-parents/13823/13 "2019-04-25T14:03:54Z")

</div>

Till Prochaska suggested in Slack to use a custom page model to solve this and it works:

```auto
  class ExhibitionPage extends Page {

    public function allImages() {
      return $this->images()->add($this->site()->find('images')->images());
    }

  }

```

Then in the files field I added:

`query: page.allImages`
