So you want to use ACF fields in your template and created a repeater and some regular fields and when you go to the template and you want to know what to do, sage10 has some new tricks to learn. I learn them the tuff way, but i will leave here my discoveries so you can have a starting point and then the sage rockstars can teach us how to improve this, if necessary.
step 1
protected $acf = true; doesn’t work anymore, instead of that you need to use Acorn
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
use Roots\Acorn\View\Composers\Concerns\AcfFields;
class App extends Composer {
use AcfFields;
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'*',
];
/**
* Data to be passed to view before rendering.
*
* @return array
*/
public function with()
{
return [
'fields' => collect($this->fields())->toArray()
];
}
}
Notice the important parts:
- you need to use Roots\Acorn\Concerns\AcfFields
- instead of protected $acf = true you now need to type use AcfFields
- thanks to the new view composer method, you will return in your with function the fields array with all the ACF stuff.
Please notice the following, that is very important:
the $fields variable is an Illuminate\Support\Fluent type of object, not an array or an object so you need to collect the data and prepare it as you liked it. in my case i did it as an array, so you can access the data in the template like:
@foreach($fields['acf_repeater'] as $object)
{{$object['property']['value_you_want_to_print']}}
@endforeach
I hope this serves you as a starting point. I had to learn a lot of laravel to realized where was my error