Support

Account

Home Forums Feature Requests Allow Dot Notation for Accessing Field Data inside of Group Fields

Unread

Allow Dot Notation for Accessing Field Data inside of Group Fields

  • The DX of interacting with the subfields inside of group fields is a little clunky, often requiring that you store the entire group value in variable and then use array notation on it.

    If often find the clunkiness of this (the way it breaks up my template mark-up) dissuades me from using a group field even when it would be appropriate or useful in the back-end.

    I’d like to propose allowing the use of dot notation in get_field and the_field functions to access the subfields of groups. This would allow us to write templates in a more ergonomic way.

    For example,

    `php
    <?php

    $address = get_field( ‘address’ );

    ?>

    <p>
    <?php echo esc_html( $address[‘street’] ); ?>
    </p>

    <p>
    <?php echo esc_html( $address[‘city’] ); ?>
    </p>
    `

    Would be equivalent to,

    `php

    <p>
    <?php the_field( ‘address.street’ ); ?>
    </p>

    <p>
    <?php the_field( ‘address.city’ ); ?>
    </p>
    `

    For backwards compatibility I’d assume there’d need to be some mechanism for ensuring this isn’t overriding a field which does have the name of ‘address.street’ (if periods are allowed in field names?).

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.