From bc0c045fa1c8dd3aa3d71c2ddf30e115d907b666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ca=C5=82ka?= <25438601+rafaucau@users.noreply.github.com> Date: Thu, 29 Jan 2026 02:13:58 +0100 Subject: [PATCH 1/3] Document Blade rendering for block.json Added a section on using the `render` field in block.json for Blade templates. --- acorn/rendering-blade-views.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/acorn/rendering-blade-views.md b/acorn/rendering-blade-views.md index 8ee3fc88..57703226 100644 --- a/acorn/rendering-blade-views.md +++ b/acorn/rendering-blade-views.md @@ -57,6 +57,30 @@ add_filter('register_block_type_args', function ($args, $name) { }, 10, 2); ``` +### block.json `render` field with Blade templates + +If you're registering blocks using `block.json` with a `render` field pointing to a Blade template (e.g. `"render": "file:./render.blade.php"`), you can automatically handle the rendering with a single filter: +``` +add_filter('register_block_type_args', function (array $args, string $name): array { + if (empty($args['render_callback']) || ! ($args['render_callback'] instanceof \Closure)) { + return $args; + } + + $reflector = new \ReflectionFunction($args['render_callback']); + $renderCallbackVariables = $reflector->getStaticVariables(); + + if (array_key_exists('template_path', $renderCallbackVariables) && str_ends_with($renderCallbackVariables['template_path'], '.blade.php')) { + $args['render_callback'] = function ($attributes, $content, $block) use ($renderCallbackVariables) { + return view() + ->file($renderCallbackVariables['template_path'], compact('attributes', 'content', 'block')) + ->render(); + }; + } + + return $args; +}, 1, 2); +``` + ## Rendering emails with Blade templates The following example uses the `resources/views/emails/welcome.blade.php` template file customizing the new WordPress user notification emails: From ebae8272c12b853b31182cf56a4900d949e14cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ca=C5=82ka?= <25438601+rafaucau@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:42:41 +0100 Subject: [PATCH 2/3] add missing `php` --- acorn/rendering-blade-views.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acorn/rendering-blade-views.md b/acorn/rendering-blade-views.md index 57703226..9e3e9166 100644 --- a/acorn/rendering-blade-views.md +++ b/acorn/rendering-blade-views.md @@ -60,7 +60,7 @@ add_filter('register_block_type_args', function ($args, $name) { ### block.json `render` field with Blade templates If you're registering blocks using `block.json` with a `render` field pointing to a Blade template (e.g. `"render": "file:./render.blade.php"`), you can automatically handle the rendering with a single filter: -``` +```php add_filter('register_block_type_args', function (array $args, string $name): array { if (empty($args['render_callback']) || ! ($args['render_callback'] instanceof \Closure)) { return $args; From 11caaa0b7613cce994e5b3b4f323b26dedda7c18 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Mon, 2 Feb 2026 10:52:41 -0600 Subject: [PATCH 3/3] Update date_modified and authors in documentation Updated the date_modified and added a new author. --- acorn/rendering-blade-views.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/acorn/rendering-blade-views.md b/acorn/rendering-blade-views.md index 9e3e9166..677db73d 100644 --- a/acorn/rendering-blade-views.md +++ b/acorn/rendering-blade-views.md @@ -1,11 +1,12 @@ --- -date_modified: 2023-04-03 13:18 +date_modified: 2026-02-02 12:00 date_published: 2023-02-21 11:30 description: Render Blade templates anywhere in WordPress using the `view()` helper function. Examples for Gutenberg blocks, ACF blocks, and email notifications. title: Rendering Blade Views in WordPress authors: - ben - chuckienorton + - rafaucau - strarsis - talss89 --- @@ -60,6 +61,7 @@ add_filter('register_block_type_args', function ($args, $name) { ### block.json `render` field with Blade templates If you're registering blocks using `block.json` with a `render` field pointing to a Blade template (e.g. `"render": "file:./render.blade.php"`), you can automatically handle the rendering with a single filter: + ```php add_filter('register_block_type_args', function (array $args, string $name): array { if (empty($args['render_callback']) || ! ($args['render_callback'] instanceof \Closure)) {