I’m working on a custom “image grid” block. I know there’s a built-in “Image Gallery” block but unfortunately the details of what I’m needing are quite different.
I’ve run into an issue with the conditional (when) property:
imageGrid:
name: Image Grid
icon: dashboard
fields:
image_interaction_type:
label: Image Interaction Type
type: radio
default: lightbox
options:
lightbox: Lightbox
link: Link
images:
label: Images
type: structure
fields:
link:
type: url
# Problem here... This is not working
when:
image_interaction_type: 'link'
This should be working, no? What might I be doing wrong?
Maybe the problem is related to the conditional field being in a structure (and the condition referencing a field outside of it, in the block’s context)?
The goal is to only show the link field in the structure (each image in the grid) if the block’s image_interaction_type is set to link.
I fear whenquery won’t work either. It only works if the field is either in the same fieldset (like any field that is together in the structure with the link field) or a field at the page root level, but not an “intermediate” level like the block form.
Unfortunately it doesn’t look that trivial to get “correct” scoping working with how the panel currently works. Maybe the core when property has a similar problem…
I don’t have time to try it out, but what about having a hidden AND disabled field inside the structure that gets its value from a outside the scope, and then base the condition on this intermediate field instead?
Thank you Sonja. I have already considered this, but unfortunately duplicates to much code on my end. My structure is a bit too… big Maybe using a structure is not the best choice in my case in the first place. But thanks anyway!