Show files in a blueprint based on field value of the file

Hi,

I am trying to create a section in a blueprint where image files appear that were “selected” and alow them to be sortable to create a curated gallery.

The setup

  • A parent called paintings with several child pages for each year.
  • Every year contains image files of painting in that year.
  • Each painting has a txt file with several data fields, one of which is a toggle field.
  • The toggle field allows you to selects the painting to show in the curated selection.

Blueprint for year:

Title: Year
sections:
    files:
        headline: Paintings
        type: files
        template: painting
        sortable: true

The aim
Display these selected paintings on the paintings blueprint so that they can be sorted manually.

selected_artwork:
    type: filesdisplay
    query: site.index.files.template("painting").filterBy('selected', true)

Things I have tried

01 The FilesDisplay Section plugin.
Works a treat, but you can’t manually sort the files - as it says in the description of the plugin.
Is there a reason why the sorting is not possible? The manual sorting is crucial for my client.

02 A collection
In collections/paintings.php

return function ($site) {
    return $site
        ->find('paintings')
        ->children()
        ->images()
        ->template('painting')
        ->filterBy('selected', true);
};

In blueprint

selected_artwork:
    type: files
    query: kirby.collection('paintings')
    sortable: true

The collection gets the correct files, but nothing shows up in the blueprint. Unless I change the type to radio, and then they do show up. But I don’t want radio buttons.

03 A structured field on the year pages

Title: Year
fields:
    paintings:
    label: Paintings
    type: structure
    fields:
        artwork_title:
            label: Title
            type: text
        artwork_image:
            label: Image
            type: files
        selected:
            label: Display in Selected Works?
            type: toggle
            text: ['No', 'Yes']

This makes it easy to toggle paintings on or off, but I have no idea how to pick an item from a structured field.

So, if anyone has ideas. I am all ears.

Thank you.

You can only sort your files within their folders, which you do with the section in the individual years.

If you want to select images from all these year folders, you can use a files field. It allows you to use a query to fetch all images from the subpages. The user can select from those images and sort them (no need for a structure field).

At the end of that document you find how to use this field in your template.

Hi,

I tried that, but nothing is showing up.

gallery:
    type: files
    query: site.find('paintings').children.files.filterBy('selected', true)

It says no Files selected. I am not getting the choose box.

Where does this selected field come from?

That’s a field attached to the file (*.jpg.txt).
I would like to select all the files from the child pages that have this toggle field set to true.

Do files show up if you just query:

gallery:
  type: files
  query: site.find('paintings').children.files

Do I get this right that you want to select files from already selected files? Or do you just want to display them in the Panel?

First nothing showed up. At least I thought so.
But I did something similar to that on a previous site, so I checked the panel there to see what it looked like, and I am stupid. The selected files are there, so it works.

Ideally I would not have to select the selected files again, but it works that way, and you can sort them manually. So great.

Thanks again. Especially at this time of the night.

Hm, that’s weird. Could you post the complete blueprint with this gallery field?

Sorry, I have edited my previous post, because I was too quick to assume it wasn’t working, when it fact it did.