diff --git a/formwork/src/View/View.php b/formwork/src/View/View.php index ff22624ad..6d3da58f2 100644 --- a/formwork/src/View/View.php +++ b/formwork/src/View/View.php @@ -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 * @@ -296,6 +310,8 @@ protected function output(): void if (isset($this->layout)) { $this->layout->vars = $this->vars; + $this->layout->blocks = $this->blocks; + $contents = ob_get_contents(); if ($contents === false) {