CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.2 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

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.

Namespace: Cake\View

Constants

  • string
    APPEND ¶
    'append'

    Append content

  • string
    OVERRIDE ¶
    'override'

    Override content

  • string
    PREPEND ¶
    'prepend'

    Prepend content

Property Summary

  • $_active protected
    string[]

    The active blocks being captured.

  • $_blocks protected
    string[]

    Block content. An array of blocks indexed by name.

  • $_discardActiveBufferOnEnd protected
    bool

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

Method Summary

  • active() public

    Get the name of the currently open block.

  • concat() public

    Concat content to an existing or new block. Concating to a new block will create the block.

  • end() public

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

  • exists() public

    Check if a block exists

  • get() public

    Get the content for a block.

  • keys() public

    Get the names of all the existing blocks.

  • set() public

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

  • start() public

    Start capturing output for a 'block'

  • unclosed() public

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

Method Detail

active() ¶ public

active(): string|null

Get the name of the currently open block.

Returns
string|null

concat() ¶ public

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.

Parameters
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.

Returns
void

end() ¶ public

end(): void

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

Returns
void
See Also
\Cake\View\ViewBlock::start()

exists() ¶ public

exists(string $name): bool

Check if a block exists

Parameters
string $name

Name of the block

Returns
bool

get() ¶ public

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

Get the content for a block.

Parameters
string $name

Name of the block

string $default optional

Default string

Returns
string

keys() ¶ public

keys(): string[]

Get the names of all the existing blocks.

Returns
string[]

set() ¶ public

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.

Returns
void

start() ¶ public

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();

Parameters
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.

Returns
void
Throws
Cake\Core\Exception\CakeException
When starting a block twice

unclosed() ¶ public

unclosed(): string[]

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

Returns
string[]

Property Detail

$_active ¶ protected

The active blocks being captured.

Type
string[]

$_blocks ¶ protected

Block content. An array of blocks indexed by name.

Type
string[]

$_discardActiveBufferOnEnd ¶ protected

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

Type
bool
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs