diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index ce35bae0f..0e8b04b31 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -827,12 +827,10 @@ class View extends Object { $data = $this->viewVars; } $this->_current = $viewFile; + $initialBlocks = count($this->Blocks->unclosed()); $this->getEventManager()->dispatch(new CakeEvent('View.beforeRenderFile', $this, array($viewFile))); $content = $this->_evaluate($viewFile, $data); - if ($this->Blocks->active()) { - throw new CakeException(__d('cake_dev', 'The "%s" block was left open.', $this->Blocks->active())); - } $afterEvent = new CakeEvent('View.afterRenderFile', $this, array($viewFile, $content)); //TODO: For BC puporses, set extra info in the event object. Remove when appropriate $afterEvent->modParams = 1; @@ -843,11 +841,16 @@ class View extends Object { $this->_stack[] = $this->fetch('content'); $this->assign('content', $content); - $content = $this->_render($this->_parents[$viewFile], $data); - + $content = $this->_render($this->_parents[$viewFile]); $this->assign('content', array_pop($this->_stack)); } + $remainingBlocks = count($this->Blocks->unclosed()); + + if ($initialBlocks !== $remainingBlocks) { + throw new CakeException(__d('cake_dev', 'The "%s" block was left open. Blocks are not allowed to cross files.', $this->Blocks->active())); + } + return $content; } diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index 51f5e77bb..fe725f25c 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -145,4 +145,13 @@ class ViewBlock { public function active() { return end($this->_active); } + +/** + * Get the names of the unclosed/active blocks. + * + * @return array An array of unclosed blocks. + */ + public function unclosed() { + return $this->_active; + } }