From d4c8c3b985d6d88dbd7a8631f691f295fc081b50 Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 16 Jan 2026 06:18:33 +0100 Subject: [PATCH 1/3] Add support for closures as Cascade content --- src/View/Cascade.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/View/Cascade.php b/src/View/Cascade.php index 85758fc158e..32dd9cc0eb5 100644 --- a/src/View/Cascade.php +++ b/src/View/Cascade.php @@ -158,6 +158,10 @@ protected function hydrateContent() return $this; } + if ($this->content instanceof \Closure) { + $this->content = call_user_func($this->content); + } + $variables = $this->content instanceof Augmentable ? $this->content->toDeferredAugmentedArray() : $this->content->toArray(); From c420f7a931f2b2737817af8d4d0d73b4b10f4a23 Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 16 Jan 2026 06:30:56 +0100 Subject: [PATCH 2/3] Add test --- tests/View/CascadeTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/View/CascadeTest.php b/tests/View/CascadeTest.php index 2b0c3e35b40..da90e12c544 100644 --- a/tests/View/CascadeTest.php +++ b/tests/View/CascadeTest.php @@ -410,6 +410,31 @@ public function it_hydrates_page_data() }); } + #[Test] + public function it_hydrates_content_by_closure() + { + $vars = ['foo' => 'bar', 'baz' => 'qux']; + $page = EntryFactory::id('test') + ->collection('example') + ->data($vars) + ->make(); + + $cascade = $this->cascade()->withContent(fn () => $page); + + tap($cascade->hydrate()->toArray(), function ($cascade) use ($page) { + $this->assertArrayHasKey('page', $cascade); + $this->assertEquals($page, $cascade['page']); + + // The 'page' values should also be at the top level. + // They'll be Value classes so Antlers can lazily augment them. + // Blade can prefer {{ $globalhandle->field }} over just {{ $field }} + $this->assertEquals('bar', $cascade['foo']); + $this->assertEquals('qux', $cascade['baz']); + $this->assertInstanceOf(Value::class, $cascade['foo']); + $this->assertInstanceOf(Value::class, $cascade['baz']); + }); + } + #[Test] public function it_hydrates_globals() { From 9d672789a075e2826e5798e0f2f1cc2dd5fc14fd Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Fri, 16 Jan 2026 06:43:38 +0100 Subject: [PATCH 3/3] Adjust test --- tests/View/CascadeTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/View/CascadeTest.php b/tests/View/CascadeTest.php index da90e12c544..38da72797e5 100644 --- a/tests/View/CascadeTest.php +++ b/tests/View/CascadeTest.php @@ -411,16 +411,17 @@ public function it_hydrates_page_data() } #[Test] - public function it_hydrates_content_by_closure() + public function it_hydrates_page_data_by_closure() { $vars = ['foo' => 'bar', 'baz' => 'qux']; $page = EntryFactory::id('test') ->collection('example') ->data($vars) ->make(); - $cascade = $this->cascade()->withContent(fn () => $page); + $this->assertEquals($page, call_user_func($cascade->content())); + tap($cascade->hydrate()->toArray(), function ($cascade) use ($page) { $this->assertArrayHasKey('page', $cascade); $this->assertEquals($page, $cascade['page']);