Fr3nch13/CakePHP Utilities

ViewBlock
in package

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.

Table of Contents

Constants

APPEND  = 'append'
Append content
OVERRIDE  = 'override'
Override content
PREPEND  = 'prepend'
Prepend content

Properties

$_active  : array<string|int, string>
The active blocks being captured.
$_blocks  : array<string|int, string>
Block content. An array of blocks indexed by name.
$_discardActiveBufferOnEnd  : bool
Should the currently captured content be discarded on ViewBlock::end()

Methods

active()  : string|null
Get the name of the currently open block.
concat()  : void
Concat content to an existing or new block.
end()  : void
End a capturing block. The compliment to ViewBlock::start()
exists()  : bool
Check if a block exists
get()  : string
Get the content for a block.
keys()  : array<string|int, string>
Get the names of all the existing blocks.
set()  : void
Set the content for a block. This will overwrite any existing content.
start()  : void
Start capturing output for a 'block'
unclosed()  : array<string|int, string>
Get the unclosed/active blocks. Key is name, value is mode.

Constants

APPEND

Append content

public string APPEND = 'append'

OVERRIDE

Override content

public string OVERRIDE = 'override'

PREPEND

Prepend content

public string PREPEND = 'prepend'

Properties

$_active

The active blocks being captured.

protected array<string|int, string> $_active = []

$_blocks

Block content. An array of blocks indexed by name.

protected array<string|int, string> $_blocks = []

$_discardActiveBufferOnEnd

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

protected bool $_discardActiveBufferOnEnd = false
Tags
see
ViewBlock::end()

Methods

active()

Get the name of the currently open block.

public active() : string|null
Return values
string|null

Either null or the name of the last open block.

concat()

Concat content to an existing or new block.

public concat(string $name[, mixed $value = null ][, string $mode = ViewBlock::APPEND ]) : void

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
$name : string

Name of the block

$value : mixed = null

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

$mode : string = ViewBlock::APPEND

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

exists()

Check if a block exists

public exists(string $name) : bool
Parameters
$name : string

Name of the block

Return values
bool

get()

Get the content for a block.

public get(string $name[, string $default = '' ]) : string
Parameters
$name : string

Name of the block

$default : string = ''

Default string

Return values
string

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

keys()

Get the names of all the existing blocks.

public keys() : array<string|int, string>
Return values
array<string|int, string>

An array containing the blocks.

set()

Set the content for a block. This will overwrite any existing content.

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

Name of the block

$value : mixed

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

start()

Start capturing output for a 'block'

public start(string $name[, string $mode = ViewBlock::OVERRIDE ]) : void

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
$name : string

The name of the block to capture for.

$mode : string = ViewBlock::OVERRIDE

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.

Tags
throws
CakeException

When starting a block twice

unclosed()

Get the unclosed/active blocks. Key is name, value is mode.

public unclosed() : array<string|int, string>
Return values
array<string|int, string>

An array of unclosed blocks.


        
On this page

Search results