mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Added View::startIfEmpty($name)
This commit is contained in:
parent
b75bb8ece7
commit
43d766f45c
2 changed files with 46 additions and 1 deletions
|
@ -598,6 +598,17 @@ class View extends Object {
|
||||||
return $this->Blocks->start($name);
|
return $this->Blocks->start($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start capturing output for a 'block' if it has no content
|
||||||
|
*
|
||||||
|
* @param string $name The name of the block to capture for.
|
||||||
|
* @return void
|
||||||
|
* @see ViewBlock::startIfEmpty()
|
||||||
|
*/
|
||||||
|
public function startIfEmpty($name) {
|
||||||
|
return $this->Blocks->startIfEmpty($name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append to an existing or new block. Appending to a new
|
* Append to an existing or new block. Appending to a new
|
||||||
* block will create the block.
|
* block will create the block.
|
||||||
|
|
|
@ -51,6 +51,15 @@ class ViewBlock {
|
||||||
*/
|
*/
|
||||||
protected $_active = array();
|
protected $_active = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the currently captured content be discarded on ViewBlock::end()
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @see ViewBlock::end()
|
||||||
|
* @see ViewBlock::startIfEmpty()
|
||||||
|
*/
|
||||||
|
protected $_discardActiveBufferOnEnd = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start capturing output for a 'block'
|
* Start capturing output for a 'block'
|
||||||
*
|
*
|
||||||
|
@ -68,6 +77,26 @@ class ViewBlock {
|
||||||
ob_start();
|
ob_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start capturing output for a 'block' if it is empty
|
||||||
|
*
|
||||||
|
* Blocks allow you to create slots or blocks of dynamic content in the layout.
|
||||||
|
* view files can implement some or all of a layout's slots.
|
||||||
|
*
|
||||||
|
* You can end capturing blocks using View::end(). Blocks can be output
|
||||||
|
* using View::get();
|
||||||
|
*
|
||||||
|
* @param string $name The name of the block to capture for.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function startIfEmpty($name) {
|
||||||
|
if (empty($this->_blocks[$name])) {
|
||||||
|
return $this->start($name);
|
||||||
|
}
|
||||||
|
$this->_discardActiveBufferOnEnd = true;
|
||||||
|
ob_start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End a capturing block. The compliment to ViewBlock::start()
|
* End a capturing block. The compliment to ViewBlock::start()
|
||||||
*
|
*
|
||||||
|
@ -75,6 +104,11 @@ class ViewBlock {
|
||||||
* @see ViewBlock::start()
|
* @see ViewBlock::start()
|
||||||
*/
|
*/
|
||||||
public function end() {
|
public function end() {
|
||||||
|
if ($this->_discardActiveBufferOnEnd) {
|
||||||
|
$this->_discardActiveBufferOnEnd = false;
|
||||||
|
ob_end_clean();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!empty($this->_active)) {
|
if (!empty($this->_active)) {
|
||||||
$active = end($this->_active);
|
$active = end($this->_active);
|
||||||
$content = ob_get_clean();
|
$content = ob_get_clean();
|
||||||
|
|
Loading…
Add table
Reference in a new issue