ideas icon indicating copy to clipboard operation
ideas copied to clipboard

More flexibility in nested field conditions

Open stuartcusackie opened this issue 3 years ago • 6 comments

Bug description

This probably isn't a bug. Let me know if I should move it to ideas.

I have a complicated page builder replicator:

  • Sections (replicator)
    • Full Section (fieldset)
      • Blocks (replicator)
        • Card Group (fieldset)
          • Style (field)
          • Items (replicator)
            • Link (field)
            • Icon (field)

I am trying to use field conditions to toggle the card_group.items fields, like so:

handle: link
if:
  card_group.style: 'linked'

handle: icon
if:
  card_group.style: 'iconed'

The above doesn't work. I have also tried root.style but I think root targets the top-level 'Sections' replicator.

How to reproduce

See above.

Logs

No response

Versions

Statamic 3.3.7 Solo Laravel 8.83.8 PHP 8.1.1 edalzell/blade-directives 3.7

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

No response

Additional details

No response

stuartcusackie avatar Apr 18 '22 11:04 stuartcusackie

A parent seems like the right move.

jasonvarga avatar Apr 18 '22 14:04 jasonvarga

A parent seems like the right move.

It would be an improvement but with 'parent' I don't think you would be able to access any grandparent fields. My ideal situation would be if I could use the handles of any ancestor fields, example in my case:

ITEMS (REPLICATOR)
handle: icon
if:
card_group.style: 'equals columns'
full_section.size: 'equals large'

Not sure if that's possible but, if I remember correctly, the ACF plugin for WordPress does something like this and it is useful sometimes.

stuartcusackie avatar Apr 19 '22 08:04 stuartcusackie

Using the handle to mean any field at any position won't really work. You could easily have multiple fields named the same at multiple positions. For instance, within grid rows, or replicator sets.

jasonvarga avatar Apr 19 '22 17:04 jasonvarga

You're probably right but let me try to explain my thinking. I've updated my original structure above to show fieldsets.

I was hoping that the conditional display code might be able to traverse its way up through the conditional field's ancestors and attempt to find the first corresponding fieldset (e.g. full_section.size). If a direct ancestor with the appropriate field is found then apply the conditional logic. I don't think there would ever be more than one ancestor field with the same name.

Maybe I shouldn't be nesting fields so much though. 'parent' and 'root' should be enough if I keep things simple. This problem presented for one of my first Statamic builds which has some pretty gnarly nesting.

stuartcusackie avatar Apr 19 '22 23:04 stuartcusackie

I’m having a similar issue in a project currently, and a parent in addition to root would be really cool :)

florianbrinkmann avatar Jan 23 '24 14:01 florianbrinkmann

I worked on a way to add a parent, and created a pull request: https://github.com/statamic/cms/pull/9385 Maybe you could have a look, @jasonvarga :)

florianbrinkmann avatar Jan 24 '24 09:01 florianbrinkmann