Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexibility in nested field conditions #783

Open
stuartcusackie opened this issue Apr 18, 2022 · 6 comments
Open

More flexibility in nested field conditions #783

stuartcusackie opened this issue Apr 18, 2022 · 6 comments

Comments

@stuartcusackie
Copy link

stuartcusackie commented Apr 18, 2022

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 stuartcusackie changed the title Field conditions: 'root' doesn't work in complex replicators Field conditions: Not enough flexibility. Apr 18, 2022
@stuartcusackie stuartcusackie changed the title Field conditions: Not enough flexibility. Nested field conditions: Not enough flexibility. Apr 18, 2022
@jasonvarga jasonvarga transferred this issue from statamic/cms Apr 18, 2022
@jasonvarga jasonvarga changed the title Nested field conditions: Not enough flexibility. More flexibility in nested field conditions Apr 18, 2022
@jasonvarga
Copy link
Member

A parent seems like the right move.

@stuartcusackie
Copy link
Author

stuartcusackie commented Apr 19, 2022

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.

@jasonvarga
Copy link
Member

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.

@stuartcusackie
Copy link
Author

stuartcusackie commented Apr 19, 2022

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.

@florianbrinkmann
Copy link

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

@florianbrinkmann
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants