That's because when you call $env->make('pages')
, the view isn't immediately processed. It's only processed when the render
method on the $view object is called, which is done automatically when you return it as a response, via the __toString()
method. The problem, though is that just after the page is rendered, still inside the render
method, the $sections
variable is cleared, using the flushSections
method. So you actually never have access to it.
You could try to fool it if you call the incrementRender
method before making the view, then make and render the view, get the sections and then finally decrementRender()
and flushSections()
, but this could bring unexpected results. Something like this:
// Fool it
$env->incrementRender();
$env->make('pages')->render();
$sections = $env->getSections();
// Clear it
$env->decrementRender();
$env->flushSections();