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

Feature - add fields from twig template #52

Open
brianjohnpenner opened this issue Jul 9, 2021 · 2 comments
Open

Feature - add fields from twig template #52

brianjohnpenner opened this issue Jul 9, 2021 · 2 comments

Comments

@brianjohnpenner
Copy link

I really like this package. I've been trying to figure out what it would take to add a fields object in the twig file to register the fields. This would make it possible to have single file components that can be easily added to themes. I'd be happy to give this a shot. Any ideas on what this would look like?

@palmiak
Copy link
Owner

palmiak commented Jul 9, 2021

So if I understand correctly - you would like to register all the fields and block parameters in one place, right?

As I see the logic of doing something like this (one file component), I'm not sure if maintaining fields in a twig file would something user friendly.

Overall - it wouldn't be a problem to create an array in Twig like this:

{% set array = {
  'item-1': {
    'sub-item-1': 'my-sub-item-1',
    'sub-item-2': 'my-sub-item-2',
  },
  'item-2': {
    'sub-item-1': 'my-sub-item-1',
    'sub-item-2': 'my-sub-item-2',
  },
  'item-3': {
    'sub-item-1': 'my-sub-item-1',
    'sub-item-2': 'my-sub-item-2',
  }
}
%}

and in the end you would have to use:

acf_add_local_field_group( $array );

so overall it's doable, but I really don't think that would make thing easier.

I think it would be just easier just to use something like this - https://github.com/StoutLogic/acf-builder or even the native ACF arrays.

But I'm open to ideas. I might be wrong :)

@brianjohnpenner
Copy link
Author

I'm working on a proof of concept similar to what you're suggesting right now. The reason I'd like to have everything in one file is that I'm considering a few projects where I'd like the ability to just drop in a file with a new component after the project is done. It would make it easy to build myself a component library that could be used across these projects without sharing repos.

With that array in Twig can I access those variables from PHP?

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

2 participants