Query files from different page that is referenced in another field


I would like to create two fields: one in which you can pick another page, and another one in which you can choose a file from the page that is chosen in the first field.

I implemented the first one using a pages field:

  type: pages
  query: site.index.filterBy('template', 'in', ['event']).upcoming
  max: 1

.upcoming is a custom page method that filters the pages (in this case representing events) based on the condition that the date in a date field is in the future. all this is tested and works fine.

Now for the second field I can’t figure out the query, or if this is even possible. Any ideas?

Thanks in advance,

No, that’s not possible out of the box. For a second field to query the value of the first it would be necessary that the first field is saved first.

To make this work, you would need a custom field that listens to changes of the first field.

See also: Programmatically change the content of the file field - #38 by bastianallgeier