\Cake\ViewViewBlock

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.

Summary

Methods
Properties
Constants
start()
end()
concat()
set()
get()
exists()
keys()
active()
unclosed()
No public properties found
OVERRIDE
APPEND
PREPEND
No protected methods found
$_blocks
$_active
$_discardActiveBufferOnEnd
N/A
No private methods found
No private properties found
N/A

Constants

OVERRIDE

OVERRIDE = 'override' : string

Override content

APPEND

APPEND = 'append' : string

Append content

PREPEND

PREPEND = 'prepend' : string

Prepend content

Properties

$_blocks

$_blocks : array

Block content. An array of blocks indexed by name.

Type

array

$_active

$_active : array

The active blocks being captured.

Type

array

$_discardActiveBufferOnEnd

$_discardActiveBufferOnEnd : boolean

Should the currently captured content be discarded on ViewBlock::end()

Type

boolean

Methods

start()

start(string  $name, string  $mode = \Cake\View\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();

Parameters

string $name

The name of the block to capture for.

string $mode

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.

Throws

\Cake\Core\Exception\Exception

When starting a block twice

end()

end() : void

End a capturing block. The compliment to ViewBlock::start()

concat()

concat(string  $name, mixed  $value = null, string  $mode = \Cake\View\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.

Parameters

string $name

Name of the block

mixed $value

The content for the block. Value will be type cast to string.

string $mode

If ViewBlock::APPEND content will be appended to existing content. If ViewBlock::PREPEND it will be prepended.

set()

set(string  $name, mixed  $value) : void

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. Value will be type cast to string.

get()

get(string  $name, string  $default = '') : string

Get the content for a block.

Parameters

string $name

Name of the block

string $default

Default string

Returns

string —

The block content or $default if the block does not exist.

exists()

exists(string  $name) : boolean

Check if a block exists

Parameters

string $name

Name of the block

Returns

boolean

keys()

keys() : array<mixed,string>

Get the names of all the existing blocks.

Returns

array<mixed,string> —

An array containing the blocks.

active()

active() : string|null

Get the name of the currently open block.

Returns

string|null —

Either null or the name of the last open block.

unclosed()

unclosed() : array

Get the names of the unclosed/active blocks.

Returns

array —

An array of unclosed blocks.