File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -158,6 +158,10 @@ protected function hydrateContent()
158158 return $ this ;
159159 }
160160
161+ if ($ this ->content instanceof \Closure) {
162+ $ this ->content = call_user_func ($ this ->content );
163+ }
164+
161165 $ variables = $ this ->content instanceof Augmentable
162166 ? $ this ->content ->toDeferredAugmentedArray ()
163167 : $ this ->content ->toArray ();
Original file line number Diff line number Diff line change @@ -410,6 +410,32 @@ public function it_hydrates_page_data()
410410 });
411411 }
412412
413+ #[Test]
414+ public function it_hydrates_page_data_by_closure ()
415+ {
416+ $ vars = ['foo ' => 'bar ' , 'baz ' => 'qux ' ];
417+ $ page = EntryFactory::id ('test ' )
418+ ->collection ('example ' )
419+ ->data ($ vars )
420+ ->make ();
421+ $ cascade = $ this ->cascade ()->withContent (fn () => $ page );
422+
423+ $ this ->assertEquals ($ page , call_user_func ($ cascade ->content ()));
424+
425+ tap ($ cascade ->hydrate ()->toArray (), function ($ cascade ) use ($ page ) {
426+ $ this ->assertArrayHasKey ('page ' , $ cascade );
427+ $ this ->assertEquals ($ page , $ cascade ['page ' ]);
428+
429+ // The 'page' values should also be at the top level.
430+ // They'll be Value classes so Antlers can lazily augment them.
431+ // Blade can prefer {{ $globalhandle->field }} over just {{ $field }}
432+ $ this ->assertEquals ('bar ' , $ cascade ['foo ' ]);
433+ $ this ->assertEquals ('qux ' , $ cascade ['baz ' ]);
434+ $ this ->assertInstanceOf (Value::class, $ cascade ['foo ' ]);
435+ $ this ->assertInstanceOf (Value::class, $ cascade ['baz ' ]);
436+ });
437+ }
438+
413439 #[Test]
414440 public function it_hydrates_globals ()
415441 {
You can’t perform that action at this time.
0 commit comments