Class ViewBlock
ViewBlock implements the concept of Blocks or Slots in the View layer. Slots or blocks are combined with extending views and layouts to afford slots of content that are present in a layout or parent view, but are defined by the child view or elements used in the view.
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/ViewBlock.php
Constants summary
-
string
'append'
-
string
'prepend'
Properties summary
-
$_active
protectedThe active blocks being captured.array
-
$_blocks
protectedBlock content. An array of blocks indexed by name.array
-
$_discardActiveBufferOnEnd
protectedShould the currently captured content be discarded on ViewBlock::end()boolean
Method Summary
- active() publicGet the name of the currently open block.
- append() public
Append to an existing or new block. Appending to a new block will create the block.
- concat() public
Concat content to an existing or new block. Concating to a new block will create the block.
- end() publicEnd a capturing block. The compliment to ViewBlock::start()
- exists() publicCheck if a block exists
- get() publicGet the content for a block.
- keys() publicGet the names of all the existing blocks.
- set() public
Set the content for a block. This will overwrite any existing content.
- start() publicStart capturing output for a 'block'
- startIfEmpty() publicStart capturing output for a 'block' if it is empty
- unclosed() publicGet the names of the unclosed/active blocks.
Method Detail
active()source public
active( )
Get the name of the currently open block.
Returns
mixedEither null or the name of the last open block.
append()source public
append( string $name , string $value null )
Append to an existing or new block. Appending to a new block will create the block.
Calling append() without a value will create a new capturing block that needs to be finished with View::end(). The content of the new capturing context will be added to the existing block context.
Deprecated
3.0.0 As of 2.3 use ViewBlock::concat() instead.Parameters
- string
$name
- Name of the block
- string
$value
optional null - The content for the block.
concat()source public
concat( string $name , mixed $value null , string $mode ViewBlock::APPEND )
Concat content to an existing or new block. Concating to a new block will create the block.
Calling concat() without a value will create a new capturing block that needs to be finished with View::end(). The content of the new capturing context will be added to the existing block context.
Parameters
- string
$name
- Name of the block
- mixed
$value
optional null - The content for the block
- string
$mode
optional ViewBlock::APPEND If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended.
end()source public
end( )
End a capturing block. The compliment to ViewBlock::start()
See
ViewBlock::start()exists()source public
exists( string $name )
Check if a block exists
Parameters
- string
$name
- Name of the block
Returns
booleanget()source public
get( string $name , string $default '' )
Get the content for a block.
Parameters
- string
$name
- Name of the block
- string
$default
optional '' - Default string
Returns
stringThe block content or $default if the block does not exist.
keys()source public
keys( )
Get the names of all the existing blocks.
Returns
arrayAn array containing the blocks.
set()source public
set( string $name , mixed $value )
Set the content for a block. This will overwrite any existing content.
Parameters
- string
$name
- Name of the block
- mixed
$value
- The content for the block.
start()source public
start( string $name )
Start capturing output for a 'block'
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();
Parameters
- string
$name
- The name of the block to capture for.
Throws
CakeException
When starting a block twice
startIfEmpty()source public
startIfEmpty( string $name )
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();
Parameters
- string
$name
- The name of the block to capture for.
unclosed()source public
unclosed( )
Get the names of the unclosed/active blocks.
Returns
arrayAn array of unclosed blocks.
Properties detail
$_discardActiveBufferOnEndsource
protected boolean
Should the currently captured content be discarded on ViewBlock::end()
See
ViewBlock::end()ViewBlock::startIfEmpty()
false
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-ViewBlock.html