Query conditional field

Can I query based upon the value of another field from the same blueprint?

I have a field that I can choose a gallery from the photography section (same as the starterkit)

note.yml

      # gallery
      gallery:
        type: pages
        label:
          en: Gallery
          de: Gallery
        empty:
          en: No gallery selected
          de: No gallery selected
        help:
          en: Place the {{ gallery }} tag anywhere in your text to add the selected gallery.
          de: Place the {{ gallery }} tag anywhere in your text to add the selected gallery.
        image:
          cover: true
        info: "{{ page.images.count }} image(s)"
        multiple: false
        query: kirby.page("photography").children

I then have a cover field.

note.yml

      # cover photo
      cover:
        type: files
        label:
          en: Cover
          de: Cover
        min: 1
        multiple: false
        query: "query against the selected gallery from above"
        uploads: image

I want to be able to select a gallery, and then be able to choose the cover images from the chosen gallery.

I have tried page.gallery but get the error of Invalid argument supplied for foreach()

I guess first, is this possible? If yes, where do I start looking??

I’m basically trying to do this - kirby.page(page.gallery).images

      # gallery
      gallery:
        type: pages
        label:
          en: Gallery
          de: Gallery
        empty:
          en: No gallery selected
          de: No gallery selected
        help:
          en: Place the {{ gallery }} tag anywhere in your text to add the selected gallery.
          de: Place the {{ gallery }} tag anywhere in your text to add the selected gallery.
        image:
          cover: true
        info: "{{ page.images.count }} image(s)"
        multiple: false
        query: kirby.page("photography").children

      # cover photo
      cover:
        type: files
        label:
          en: Cover
          de: Cover
        image:
          cover: true
        # min: 1
        multiple: false
        query: kirby.page(page.gallery).images

I can return all images associated to the parent page using query: kirby.page("photography").children.images just fine, but I can’t seem to find a way to only show images based upon the selection from the gallery field.

Try

page.gallery.toPage.images

Thanks.

I’ve found a slight problem with what I want to achieve here.

Both

page.gallery.toPage.images

and

kirby.page(page.gallery.toPage).images

work, however the article has to be saved and sometimes page refreshed before the query will work.

For this to work it would require the CMS to write some sort of temporary data about the changes made to the document - like instantly write the changes made to the .txt file, store old data some where, maybe the .lock file so that if the page isn’t saved it will revert any changes back to original. This way the query can always check against selections made within the document without the need for saving.

I think you would rather need a custom field that listens to changes in the other field and then queries the images on the fly

That’s an interesting option !
Any advice on how to do that ?