# Get files() of $page that come from other pages

**URL:** <https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 7, 2025, 3:17pm UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744 "2025-03-07T15:17:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schnarr.tech](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@schnarr.tech](https://forum.getkirby.com/u/schnarr.tech)\
**Post date:** [March 7, 2025, 3:17pm UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744/1 "2025-03-07T15:17:23Z")

</div>

[Here in the Docs for File Fields](https://getkirby.com/docs/reference/panel/fields/files#querying-files__querying-files-from-other-pages) is described how to query other files from other pages.

Now when I select a file from another page in my file field (which therefore resides in another folder) I cannot access this file if I call the `$page->files()` method.

What I would expect is to be able to get all the files that are being used in this page, or am I missing something?

Is there another way to achieve that?

(What I actually wanna achieve is, to display in the Panel in my [Files Section](https://getkirby.com/docs/reference/panel/sections/files) in a separate column where the individual files are being referenced, since I have a global Files section and most of my File Fields have some sort of `query` added to make sure all files that are linked multiple times within the same page aren’t actually duplicates but can be replaced with one single click in the Files Section. (that sounds really complicated if I read that…🤔))

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [March 7, 2025, 5:03pm UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744/2 "2025-03-07T17:03:42Z")

</div>

If you select files in a files field, you will need to call the specific field and apply the `->toFiles()` method to it, e.g.

```php
$page->yourFilesFileName()->toFiles()

```

Keep in mind that existing method names are reserved, to if you name your files field `files` you cannot access it via `$page->files()` as this is an [existing method](https://getkirby.com/docs/reference/objects/cms/page/files). Either choose a different name for your field or access it via `$page->content()->get('files')->toFiles()`.

You lost me a bit with that last part, I couldn’t quite follow what you are trying to achieve.

---

<div class="post-metadata">

**Author:** ![schnarr.tech](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@schnarr.tech](https://forum.getkirby.com/u/schnarr.tech)\
**Post date:** [March 12, 2025, 9:11am UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744/3 "2025-03-12T09:11:01Z")

</div>

Sorry for not being very clear…  
The issue is, that I don’t have a specific page that I can query from.

My panel is structured in a way that the files that can be selected for file fields are all stored in one folder, to be able to make sure there are no duplicate files in various different pages. Files are being referenced on different pages, therefore my client doesn’t wanna upload the files on every page again and again, if a file needs updating.  
I achieve that by adding a query to the file field and setting the uploads path:

```yml
fields:
  document:
    type: files
    query: site.index.files.filterBy('type', 'document')
    uploads:
      parent: page('document-page')

```

Then in the `Files Section` of my Panel page, which is another tab, I’m setting the parent to the same document-page as referenced above:

```yml
sections:
  someFilesSectionName:
    type: files
    parent: page('document-page')

```

(I do that by the way in this complicated way because I’m still on Kirby 3 which doesn’t have the `query` option for files sections yet…)

* * *

Now what I want to achieve is to display the page names in the `Files Section` where each file if referenced on, to be able to give the user a nice overview over all the files like so:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/1/14534cb701842c3175765f2fc501eafb31772e4a.png)

For that I need to query the files that each page obviously holds. That’s kindof where the issue starts.

Currently I am taking all pages and then checking on the files that each page provides. But, as mentioned before, this only returns the files on a file system level, not the actual files belonging to the page model.

So what I was trying, which didn’t work as expected:

```php
site()->index(true)->pluck('files')

```

* * *

Does that make a bit more sense, what I’m trying to achieve? Maybe it’s just not possible that easily, then I have to find some other workaround…

Thanks in advance!

---

<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:** [March 12, 2025, 12:11pm UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744/4 "2025-03-12T12:11:01Z")

</div>

Well, basically, for each file you would have to loop through all pages and check if it is uses in the `document` field. For that purpose, I would create a custom file method.

With a lot of files and querying the whole index multiple times, this can slow the Panel down considerably. So some sort of caching would make sense. I can remember there was a plugin related to this task, let me check.

> **[GitHub - visionbites/kirby-usage-reference: A Infosection to display all references to a page...](https://github.com/visionbites/kirby-usage-reference)**
>
> A Infosection to display all references to a page or a file in a list.

But this works a bit differently, not as info in a section.

---

<div class="post-metadata">

**Author:** ![schnarr.tech](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@schnarr.tech](https://forum.getkirby.com/u/schnarr.tech)\
**Post date:** [March 12, 2025, 2:20pm UTC](https://forum.getkirby.com/t/get-files-of-page-that-come-from-other-pages/33744/5 "2025-03-12T14:20:47Z")

</div>

Wow, awesome, thank you so much!  
This is exactly what I’m looking for.

And I thought I looked in plugins if there is something available…?!
