Files field: query images in a block that works both on page and in site

I’m having similar problems while trying to fetch images from the whole site or from another page in custom blocks. And i can’t get it to work. Does query: model.images need a page/site model?

I have a bunch of logos i uploaded to a page called /images/logos/ all with the template “logo”, cause i saw a similar suggestion by @texnixe somewhere here in the forum (i think here). Now i want to access these files in several custom blocks i use all over the site in pages, so that i don’t have to upload them to each page-folder and create redundance.

i tried

name: "007 Logos"

tabs:

  main:

    fields:

      text:
        type: textarea
        size: small
    
      logos:
        type: files
        query: site.find('logos')
        template: logo
        multiple: true
        uploads:
          template: logo

also tried a couple of these:

#parent: site.find('logos')
#query: site.images.template("logo")
#query: site.index(true).find('logos').images
#query: model.images

all not resulting in what i need. Any ideas?
Oh, i’m using kirby 4.2.0

Well, your logos page is a subpage of images (at least according to what you wrote above, so the path is images/logos and not just logos, so you need to pass that to find(). Also, the query needs to return a collection of images, not a page, so we need to stick the images() method onto the query:

query: site.find('images/logos').images

If you also want to filter them by template:

query: site.find('images/logos').images.template('logo')
1 Like

:man_facepalming: … Thank you again Sonja! That works like expected.
To access all images of the site, i would use

 query: site.index.children.images

right? Seems to work as well, even if that might not make sense in terms of performance, but i want to understand. Still learning :slight_smile:

Yep.

1 Like