Closed smithd88 closed 9 months ago
This appears to be an order of execution issue. Defining the example
values in the fields()
method resolves the issue. However, I would love to hear if there's a better approach?
you have to call the parent constructor.
// Adding the constructor causes ACF Fields to not be registered to the block
public function __construct(Application $app)
{
// Defining the example image path in the constructor allows me to call the Roots\asset() method
$this->example['image'] = [
'alt' => 'Sample image',
'url' => asset('images/placeholder.webp'),
];
parent::__construct($app);
}
you can see a better example on the construct stub.
I attempted this, but I don't think I passed $app
back to the parent::__construct()
. This worked great. Thank you for taking the time to answer my question!
I'm having a difficult time getting my example data to reference a static image in my asset directory. It works if I define it in a constructor within my block. However, doing so results in the ACF Fields not registering to the block. Here's some code which shows what I'm attempting to do: