Roots Discourse

Sage, Gutenberg and ACF Blocks

I think I’ve documented my question above well enough for someone to take a quick look at my Gist code and be able to identify why I get the error Fatal error: Uncaught Error: Class 'Itineris\AcfGutenblocks\Plugin' not found in /app/public/wp-content/plugins/acf-gutenblocks/acf-gutenblocks.php:32.

I’m sure there’s someone out there that’s successfully implemented @codepuncher plugin. It’d be super cool if someone would be willing to help me.

And yes, from the beginning I had already tried use App\Blocks\Testimonial\Testimonial; this namespace. I’ve ran the composer command to install the plugin, in the main WordPress plugins folder, I’ve activated it. But using the exact code from the ItinerisLtd/acf-gutenblocks page, I get the error. Can plugin namespace talk to theme namespace? The solution must be simple.

From your error it looks like the plug-in itself is having trouble autoloading its own classes, which is really weird. I’m using the plug-in currently, and never ran into this issue. Are you using Bedrock? Have you tried removing and reinstalling the plug-in? The only thing I can think of is that your composer is misconfigured somehow so it isn’t properly generating an autoloader for the plug-in.

Thanks for the response, @alwaysblank. I am not using Bedrock. I’ll try reinstalling the plugin!

I’ve only tested it on Bedrock as that is what I’ve intended it to use.
Going off of that and comments above, I can only assume the issue relates to autoloading with Composer.
Have you installed it using Composer or adding it the traditional way?

I installed with composer, then went to the WP Dashboard to activate. So, it seems like the missing thing here is that I should be running Bedrock.

I originally wanted to run Bedrock, but all the tutorial setup videos had people editing all these configurations and even they were getting stumped, so I decided not to use it. But, perhaps it’s really not that complicated to setup? I use Local by Flywheel for a local server, so it’s pretty easy. My fear was that I might run into issues locally or during deployment.

Can I “upgrade” a normal Sage project to Bedrock, or would I have to start the project over?

Is there a way to render Blocks outside of the post_content block? or is this not the use case for blocks, e.g. blocks can only items inside what would be Sage’s area?

Or is it a matter of me rejigging the layout blade.php to remove the container and then work with the application that way?

Hi there. I’m trying to use @MWDelaney sage-acf-wp-blocks but I’m stuck.
I followed the README, the block is being enlisted and I can use it with my custom ACFs, it’s even being rendered by the sage_blocks_callback() callback, but the post content isn’t being updated, I only get the post’s data commented out.
The field post_content in the database is like this:

<!-- wp:paragraph -->
<p>Sed ut perspiciatis unde omnis iste natus Sed ut perspiciatis unde omnis iste natus:</p>
<!-- /wp:paragraph -->

<!-- wp:acf/accordion {
    "id": "block_5d7a692a5ebef",
    "name": "acf\/accordion",
    "data": {
        "accordion-items_0_heading": "Name and Lastname",
        "_accordion-items_0_heading": "field_5d7a68c978958",
        "accordion-items_0_body": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.\r\n\r\nSed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.",
        "_accordion-items_0_body": "field_5d7a68dd78959",
        "accordion-items_1_heading": "Name and Lastname",
        "_accordion-items_1_heading": "field_5d7a68c978958",
        "accordion-items_1_body": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit.",
        "_accordion-items_1_body": "field_5d7a68dd78959",
        "accordion-items": 2,
        "_accordion-items": "field_5d7a689778957"
    },
    "align": "",
    "mode": "edit"
} /-->

I even tried to What am I missing?

I even tried with @codepuncher’s plugin but the issue is the same, so I think that there’s something in my environment.
I’m using Sage 9 (latest) with WP 5.2.3 and ACFPro 5.8.4.

Any hint?

Just sharing the best solution I’ve found :slight_smile:

Uh… I don’t get it, it’s the one I’m using and the one that’s giving me problems :confused:

For the last couple of months that package has been giving me this error:
Undefined index: className

So I’ve been using this fork instead:
composer require "orditeck/sage9-acf-wp-blocks"

1 Like

Nailed it, at last.
get_the_content() doesn’t pass through the the_content filter and the blocks won’t render; to make them back in I had to change all {!! get_the_content() !!} occurrences in my code with @php the_content() @endphp.

1 Like

Are there any resources on the block description data? For example what are the possible values for mode, align, … What’s the use of supportsalign, supportsmode, supportsmultiple (I don’t see a difference when changing those values).

1 Like

You could use MWDelaney’s package, he stated somewhere we should use the dev-master branch for now. That solves the className issue as well.

For those that are interested, I’ve have released some new versions today for acf-gutenblocks.

0.2.1 changes:


0.3.0 changes:

New features:

  • allow choosing post types (cheers @TangRufus)
  • allow customising the blade callback method (useful for Sage 10 - thanks @alwaysblank)

Also contains some bug fixes from other contributors.

4 Likes

Just released 0.4.0 which now lets you create template variables in your Block class like so:

// Blocks/Testimonial/Testimonial.php
public function with(): array
{
    return [
        'title' => (string) get_field('title'),
        'items' => (array) get_field('items'),
    ];
}
{{-- Blocks/Testimonial/views/frontend.blade.php --}}

@unless(empty($title))
    <h2>{{ $title }}</h2>
@endunless
@foreach($items as $item)
    <p>{{ $item['title'] }}</p>
@endforeach

Also updated the readme a bit as it had some issues.

3 Likes

@ciromattia I’ve been on this for several hours and can’t figure it out. Can You write a quick tutorial and how you got it to work? I’ve got his plugin installed but I’m doing something wrong apparently because blade doesn’t work. I have blade files in ‘views/blocks/’ but blocks are not being created. Not sure why. Would you be so kind to walk me from point a) to point z). I’d love to use Gutenberg blocks for my next project. Thanks in advance.

I figured it out. I had ACF in a custom directory. :grin:

Can you also please guide me how can I create a block template? I am doing the same using this resource https://wpitech.com/create-wordpress-gutenberg-block-templates/ but it’s giving an error and I am having some programming lines in front end. This is the code
add_action( ‘init’, function() {
$args = array(
‘public’ => true,
‘label’ => ‘News’,
‘show_in_rest’ => true,
‘template_lock’ => ‘all’,
‘template’ => array(
array( ‘core/paragraph’, array(
‘placeholder’ => ‘Breaking News’,

Just wanted to say thanks for this suggestion. I was getting the same error and using this package seems to have solved it for me as well. Thanks @MWDelaney @nicooprat and everyone else for all the effort going into making it this a possibility. Extremely useful!

I prefer to have a single file that work out of the box without any hook required. just like Sage 9 controller. So I come up with this. https://github.com/WP63/ACF-Block-Loader

You just need a class file (a basic controller) and template file. that’s all. no need for hooking or anything (the code behind the scene is a bit hurt. feel free to improve.)

At the moment, it supports only few basic configuration. I’m changing this to support all configuration soon.

The Package is intended to use with Sage 9 but should as well works with anything. theoretically.

2 Likes