Using the "when" field property referencing a toggle field outside of the current field section

Hi kirby-community,

I want to modify a slideshow blueprint and add the option to have a global overlay for all slides or individual overlays for each slide. So I thought I’d add a toggle that either shows a blockEditor field above the slides (structure) and hides the blockEditor inside of the slides or vice versa.

The extra blockEditor shows and hides just fine but the blockEditor in the slides won’t show either way now. My suspicion is that I can’t reference a toggle from within a nested field section. Is that right or can you see what is wrong with my code?

name: Slideshow
icon: images

preview: zimageslider

tabs:
  # content tab
  content:
    label: 
      en: Content
      de: Inhalt
    icon: edit
    fields:

      # global overlay ein oder aus
      globalOverlayToggle: 
        type: toggle
        label: Globales Overlay
        help: Wenn eingeschaltet wird ein Overlay für alle Slides verwendet. Wenn ausgeschaltet bekommt jedes Slide ein eigenes Overlay. 

      # content blocks
      globalContentBlocks:
        extends: fields/blockEditor
        when:
          globalOverlayToggle: true

      # slideshow
      slideshow:
        label: 
          en: Slideshow items
          de: Slideshow-Elemente
        type: structure
        columns: 
          slideName:
            width: 1/4
          slideImage: 
            width: 1/4
          contentBlocks:
            width: 1/4
          slideContentPosition:
            width: 1/4
        fields:
          # content blocks
          contentBlocks:
            extends: fields/blockEditor
            when:
              globalOverlayToggle: false

No, I don’t think this will work.

I’d try out the Whenquery plugin: GitHub - rasteiner/k3-whenquery: Conditionally show fields and sections. Better.

Can’t promise anything, though, but worth a test.

wow, thanks for the quick response at this late hour! I’ll look into it. :slight_smile:

Doesn’t work unfortunately. Same issue. Great Plugin though, will keep that. Maybe I’ll come up with a different solution using that. Thanks again.

This seems to work though:

    fields:
      globaloverlaytoggle:
        type: toggle
        label: Globales Overlay
        help: Wenn eingeschaltet wird ein Overlay für alle Slides verwendet. Wenn ausgeschaltet bekommt jedes Slide ein eigenes Overlay.
      # content blocks
      globalContentBlocks:
        type: blocks
        whenQuery: globaloverlaytoggle = true
      # slideshow
      slideshow:
        label:
          en: Slideshow items
          de: Slideshow-Elemente
        type: structure
        fields:
          # content blocks
          text:
            type: text
          contentBlocks:
            type: blocks
            whenQuery: globaloverlaytoggle = false

That’s what I tried and just retried. The contentBlocks in the slideshow is now always hidden.

As a workaround I added a class to the slides in the snippet when the toggle = true to hide the individual overlays of the slides and added a note to those in the blueprint saying they will be hidden when the toggle is active. Not as clean but for now this will have to do I guess.

I’ll attach my current code in case I missed something:

name: Slideshow
icon: images

preview: zimageslider

tabs:
  # content tab
  content:
    label: 
      en: Content
      de: Inhalt
    icon: edit
    fields:

      # global overlay ein oder aus
      globalOverlayToggle: 
        type: toggle
        label: Globales Overlay
        help: Wenn eingeschaltet wird ein Overlay für alle Slides verwendet. Wenn ausgeschaltet bekommt jedes Slide ein eigenes Overlay. 

      # content blocks
      globalContentBlocks:
        extends: fields/blockEditor
        whenQuery: globaloverlaytoggle = true
       # when:
       #   globalOverlayToggle: true

      # slideshow
      slideshow:
        label: 
          en: Slideshow items
          de: Slideshow-Elemente
        type: structure
        columns: 
          slideName:
            width: 1/4
          slideImage: 
            width: 1/4
          contentBlocks:
            width: 1/4
          slideContentPosition:
            width: 1/4
        max: 10
        help: 
          en: Maximum 10 items allowed.
          de: Maximal 10 Artikel erlaubt.
        fields:
          # slide name
          slideName:
            label: Slide name
            type: text
            default: Slide
          # slide image
          slideImage:
            label: 
              en: Slide image
              de: Slide Bild
            extends: fields/image
            multiple: false

          # content blocks
          contentBlocks:
            extends: fields/blockEditor
            help: "HINWEIS: Diese Inhaltsblöcke werden nicht angezeigt wenn das globale Overlay aktiviert ist."
            whenQuery: globaloverlaytoggle = false

:thinking:



:woman_shrugging:

huh… weird. :hushed: I’m using the Zero One theme maybe some plugin is interfering with the whenquery plugin. :thinking: I saw this in the known issues of whenquerry:

“This plugin extends and replaces the default Blocks and Layout field types. This means that it is not compatible with other plugins that do the same.”

Maybe that’s the case here. Oh well, I’ll leave my workaround in place for now and may revisit this. But at least we have prove that it probably would work in most cases if anyone else tries this. :+1: Thanks again and good night. :wave: