Home Forums ACF PRO ACF as modules


ACF as modules

  • I have been using ACF Groups to build modular websites. The idea is that each Field Group is a module and in the theme folder I have a template file/folder for each group. I can load scripts, styles, and any other settings based on the group key.

    Everything works, but there’s one big limitation…

    A field group can only show up once per page.

    To circumvent this, I would need to duplicate that field group. But eventually duplicating field groups can cause a lot of redundancy, as a duplicated group still uses the same template file, and the same settings… just a different key.

    I have been looking at other functions available in the plugin, and also at how the local json files are handled. I figured that I could define my own groups as an object or array and then use a function like:

    acf_write_json_field_group($field_group) to create my own json files on the fly. And then use the sync method to automatically sync those groups without using the UI.

    It looks like this could work, but I am wondering if there are better approaches to what I am trying to accomplish?

    Ideally, I would like to skip the json file and just generate these groups from an object, which would allow me to create field groups on the fly, by passing different parameters as needed.

    Any ideas? Suggestions?

    Another approach I have used in the past, is to make one big field group with one flexible content field, and then each acf layout would correspond to a template file. But that means that all pages would start without any fields, and I am not in the business of making themes where the user has an overwhelming amount of options (which imo it makes for bad usability).

  • Hi @danielpush10-com

    I believe the flexible content would be the best choice for this kind of situation. You can also create a field group to show the initial fields and use the flexible content if the users need to add additional modules.

    If you want to use the JSON method, I suggest you use the PHP method instead. This page should give you more idea about it: That way you don’t need to create and sync any field group.

    I hope this makes sense 🙂

  • Thanks for the reply. I didn’t know I could register fields directly with PHP. That would be ideal. Thanks.

  • I am also facing the same issue , can you tell me that how should I resolve this?

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘ACF as modules’ is closed to new replies.