Roots Discourse

Using ACF Builder with Sage


#21

@Log1x this looks awesome! I installed and I’m trying it out, but I can’t seem to get any output. I created a foreach loop that is pulling in partials based on acf_fc_layout (based on the recommendations of nathobson and jasonbaciulis):

@foreach ($components as $component)
  @include('partials/builder/'.$component->acf_fc_layout)
@endforeach

Here are the contents of the partial, which is successfully loading, but not printing any of the field values:

<div class="image-text-overlay">
  @group('image-text-overlay')
    <div>
      <h2>@sub('heading')</h2>
    </div>
    <div><img src="@sub('image', 'url')" alt="@sub('image','alt')"></div>
  @endgroup
  @debug
</div>

Here’s what’s in debug:

Anything I might be missing?


#22

Did you figure this out? Is the group key supposed to be image_text_overlay?

Does {!! var_dump(have_rows('image-text-overlay')) !!} return true?

For what it’s worth, https://github.com/Log1x/sage-directives now has docs & has been updated. :slight_smile:


#24

Hey Brandom, I really appreciate your effort to help us write such cleaner and more maintainable code. Although there’s one big gotcha that took me hours to debug that I think you should warn people when using this technique. It took me a long time to figure out why the custom fields were not working in a production server but were working in my local mac environment, it turned out to be all about the letter case in the file and folder names.

As a quick example, if you create a file named Button.php and try to call get_field_partial('components.button') , it won’t work because it will look for a button.php (lower cased). Same thing for folder names such as Fields and fields .

I think that because all other files and folders around the app folder are all capitalized (since they are classes), I also happened to capitalized the custom fields. Big problem is that it didn’t care at all in my mac environment, but the moment I’ve uploaded it to the linux production server nothing worked hehe, taking some good hours to find out why and update everything.

Thanks again for the awesome article!


#25

I want to reuse fields on multiple options pages.
The catch is that options are basically all one page as far as ACF is concerned, so they need unique keys per options page.

I’m adding normal fields, not flexible content fields.

I tried both the ->addFields($header) method and the ->addFields(get_field_partial('partials.header')) method, and tried setting the ‘key’ on the FieldsBuilder and addFields.

With the above attempts, the same keys get used (can tell this quickly because the fields on new options pages are filled out already with text i entered through wp-admin on old options pages)

Is there a way to add a prefix to the key or change the key after doing addFields? I don’t see any mention in the ACFBuilder docs about prefixing a key. Or am I going about this the wrong way?

Thanks

Edit: This seems more of an ACFBuilder question so I submitted it on their repo. I’ll update here if a solution is found.


#26

With the current implementation of ->addFields, I don’t see a sane way in ACF Builder’s source to pull this off for the entire field group; especially with the FieldsBuilder instance protecting $config and $fieldManager.

I can see this being useful if implemented though as shown in the issue you opened.