Global and local files in "files" field

Hello,

I would like to show global files uploaded via the site blueprint + local files uploaded on the current subpage. Showing files from site does work:

query: site.images

But how to add the images uploaded to the subpage folder?

Thank you!

afaik all core sections (files and pages) need one and only one parent object.

but maybe @texnixe plugin: https://github.com/texnixe/k3-filesdisplay-section
can handle having a collection object as a root (since her plugin is based on one for pages that does allow this).

query: kirby.collection('myfiles')

But the plugin is a section, not a files field.

In a field you would use a query, anyway, not a parent.

another idea would be to override the images method in a pagemodel. in that a merged array could be returned. but i am not sure about this having side-effects like when trying to remove a file.

That will then have effects on the frontend as well, so I wouldn’t do it. Better use a general method, but it should actually be possible to use collections in a query, but I’m not sure how a collection behaves when trying to use the current page.

I’d go with a custom page method that combines the page’s files with the site’s files.

1 Like

I used a page method to combine the files like this

    'pageMethods' => [
        'combinedFiles' => function () {

            return $this->files()->add($this->site()->files());

        }
    ]

And then used the new function in my blueprint query:

query: page.combinedFiles

Thank you!

2 Likes