I have created a structure field that holds multiple image galleries. Within each gallery I would like to be able to select on of the gallery images to be marked as active.
I am using the following code but don’t know what to query for or if this is possible at all.
I think your featured field should simply be a toggle field that is set to true for the selected image in the first field if the user wants to feature it.
Per structure item you select one image and for that image, you set if this should be featured or not. Otherwise using a structure wouldn’t even make sense here.
The alternative would be to use a files section and store which image should be featured in the meta data.
The user must be able to create separate galleries that have a max of 5 images. After he decided on which 5 images go to the specific gallery he then selects one of them to be featured.
Oh, ok, but the problem is that you won’t be able to query the files from the blueprint. You would indeed need JavaScript to be able to query what has been selected in the first field in the second.
Instead of selecting the file, why not ask the user to put the featured image first (they can sort the images in the files field after all). Unless you need the order plus a featured image. If the featured image shouldn’t be the first image as well, then you will have to go down the JS route, I think.
Or use a nested structure field with the toggle field as explained above.
Because I need to apply separate styling to the featured image while retaining its order in the gallery. This is such a stupid request the more I think about it.
That means that for each gallery, the user has to select each image separately, and then for one of the items set the featured toggle to true. If the user happens to select more than one as featured, you have to get the first featured image.