// lib/Cake/View/View.php
public function renderLayout($content, $layout = null) {
$layoutFileName = $this->_getLayoutFileName($layout);
if (empty($layoutFileName)) {
return $this->Blocks->get('content');
}
if (empty($content)) {
$content = $this->Blocks->get('content');
} else {
$this->Blocks->set('content', $content);
}
$this->getEventManager()->dispatch(new CakeEvent('View.beforeLayout', $this, array($layoutFileName)));
$scripts = implode("\n\t", $this->_scripts);
$scripts .= $this->Blocks->get('meta') . $this->Blocks->get('css') . $this->Blocks->get('script');
$this->viewVars = array_merge($this->viewVars, array(
'content_for_layout' => $content,
'scripts_for_layout' => $scripts,
));
$title = $this->Blocks->get('title');
if ($title === '') {
if (isset($this->viewVars['title_for_layout'])) {
$title = $this->viewVars['title_for_layout'];
} else {
$title = Inflector::humanize($this->viewPath);
}
}
$this->viewVars['title_for_layout'] = $title;
$this->Blocks->set('title', $title);
$this->_currentType = static::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layoutFileName));
$this->getEventManager()->dispatch(new CakeEvent('View.afterLayout', $this, array($layoutFileName)));
return $this->Blocks->get('content');
}