Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions formwork/src/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ public function define(string $block): void
ob_start();
}

/**
* Return whether the specified block is defined
*
* @throws RenderingException If called outside of rendering context
*/
public function defined(string $block): bool
{
if (!$this->rendering) {
throw new RenderingException(sprintf('%s() is allowed only in rendering context', __METHOD__));
}

return isset($this->blocks[$block]);
}

/**
* End the capturing of last block
*
Expand Down Expand Up @@ -296,6 +310,8 @@ protected function output(): void

if (isset($this->layout)) {
$this->layout->vars = $this->vars;
$this->layout->blocks = $this->blocks;

Comment on lines 311 to +314
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning $this->layout->blocks = $this->blocks and then immediately writing $this->layout->blocks['content'] = ... forces PHP to separate/copy the whole $blocks array due to copy-on-write. If blocks can be large, consider adding the content entry before assigning blocks to the layout (or otherwise avoid writing to the layout blocks array right after the assignment) to prevent an unconditional array copy when rendering with a layout.

Copilot uses AI. Check for mistakes.
$contents = ob_get_contents();

if ($contents === false) {
Expand Down