Rendering custom Gutenberg blocks using Blade

I created a site using Bedrock + Sage 10 + Acorn. Now, I’m trying to use Clover to render Gutenberg blocks using Blade. What I’ve tried so far:

'render_callback' => function ($attributes, $content) {
    echo \Roots\view('example', compact('attributes', 'content'));
    //echo \Roots\view('example', compact('attributes', 'content'))->render();
},

But both results same error:

Unrecognized extension in file: example

This newly added doc page dedicated to rendering views should be helpful:

Thanks for the feedback @strarsis, but I’m getting the same error. Here’s my complete filter hook (added inside method register of the class BlockServiceProvider):

add_action('init', function () use ($entrypoints) {
    wp_register_script(
        'clover/editor',
        plugins_url('../dist/js/editor.js', dirname(__FILE__)),
        $entrypoints->editor->dependencies,
        null,
        true,
    );

    register_block_type( 'clover/howdy', array(
        'api_version' => 2,
        'editor_script' => 'clover/editor',
        'render_callback' => function ($attributes, $content) {
            return view('blocks/example', compact('attributes', 'content'));
        },
    ));
});

I think I understand the problem: return view('blocks/example', compact('attributes', 'content')); is looking for the blade file in the theme folder, not in the plugin folder. Is it possible to change this?

1 Like

try Package Development - Laravel - The PHP Framework For Web Artisans

2 Likes