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.
string
'append'
Append content
string
'override'
Override content
string
'prepend'
Prepend content
array<string>
The active blocks being captured.
array<string>
Block content. An array of blocks indexed by name.
bool
Should the currently captured content be discarded on ViewBlock::end()
Get the name of the currently open block.
Concat content to an existing or new block. Concating to a new block will create the block.
End a capturing block. The compliment to ViewBlock::start()
Check if a block exists
Get the content for a block.
Get the names of all the existing blocks.
Set the content for a block. This will overwrite any existing content.
Start capturing output for a 'block'
Get the unclosed/active blocks. Key is name, value is mode.
active(): string|null
Get the name of the currently open block.
string|null
concat(string $name, mixed $value = null, string $mode = ViewBlock::APPEND): void
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.
string
$name Name of the block
mixed
$value optional The content for the block. Value will be type cast to string.
string
$mode optional If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended.
void
end(): void
End a capturing block. The compliment to ViewBlock::start()
void
exists(string $name): bool
Check if a block exists
string
$name Name of the block
bool
get(string $name, string $default = ''): string
Get the content for a block.
string
$name Name of the block
string
$default optional Default string
string
keys(): array<string>
Get the names of all the existing blocks.
array<string>
set(string $name, mixed $value): void
Set the content for a block. This will overwrite any existing content.
string
$name Name of the block
mixed
$value The content for the block. Value will be type cast to string.
void
start(string $name, string $mode = ViewBlock::OVERRIDE): void
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();
string
$name The name of the block to capture for.
string
$mode optional If ViewBlock::OVERRIDE existing content will be overridden by new content. If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended.
void
Cake\Core\Exception\CakeException
unclosed(): array<string>
Get the unclosed/active blocks. Key is name, value is mode.
array<string>
The active blocks being captured.
array<string>
Block content. An array of blocks indexed by name.
array<string>
Should the currently captured content be discarded on ViewBlock::end()
bool
© 2005–present 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/4.4/class-Cake.View.ViewBlock.html