Skip to content

Commit

Permalink
Fix issue with rendering elements inside blocks.
Browse files Browse the repository at this point in the history
Fixes exceptions being raised when you tried to render
elements inside blocks.  Instead compare the number of open blocks.
This should not change before/after rendering a view.
  • Loading branch information
markstory committed Dec 30, 2011
1 parent 3478f8a commit 6c902a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/Cake/View/View.php
Expand Up @@ -827,12 +827,10 @@ protected function _render($viewFile, $data = array()) {
$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;
Expand All @@ -843,11 +841,16 @@ protected function _render($viewFile, $data = array()) {
$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;
}

Expand Down
9 changes: 9 additions & 0 deletions lib/Cake/View/ViewBlock.php
Expand Up @@ -145,4 +145,13 @@ public function keys() {
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;
}
}

0 comments on commit 6c902a1

Please sign in to comment.