0
votes

At the moment all the ACF fields attached to a post get attached to the TimberPost object without any grouping. I'd like to be able to separate them based on what Field Group they belong to. That way I could create cleaner templates in Twig. I.e.:

Let b be the name of the Field Group which has two fields field1 and field2

Instead of current solution: {{ post.b_field1}} and {{ post.b_field2}}

Can we do this: {{ post.b.field1}} and {{ post.b.field2}}

I know I can get the fields for specific field group using acf_get_fields($field_group_id) but the result is an array instead of a Timber object. Is there a way to feed those fields into a TimberPost object?

1

1 Answers

0
votes

SpuriouslyAwake: Try extending TimberPost with your own class, it'd look something like...

class MyPost extends TimberPost {

    function field_group($field_group_id) {
        return acf_get_fields($field_group_id);
    }
}

In theory, this would let you do something like.. {{ post.field_group('b').field1 }} (in theory, that's untested code, but you get the gist)