diff --git a/system/View/View.php b/system/View/View.php index eac90bb7ec4a..8062974d40ad 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -480,9 +480,10 @@ public function renderSection(string $sectionName) return; } - foreach ($this->sections[$sectionName] as $contents) + foreach ($this->sections[$sectionName] as $key => $contents) { echo $contents; + unset($this->sections[$sectionName][$key]); } } diff --git a/tests/system/View/ViewTest.php b/tests/system/View/ViewTest.php index 4c40cae75342..4b5606b9d4d5 100644 --- a/tests/system/View/ViewTest.php +++ b/tests/system/View/ViewTest.php @@ -276,6 +276,18 @@ public function testRenderLayoutExtendsCorrectly() $this->assertContains($expected, $view->render('extend')); } + public function testRenderLayoutExtendsMultipleCalls() + { + $view = new View($this->config, $this->viewsDir, $this->loader); + + $view->setVar('testString', 'Hello World'); + $expected = "

Open

\n

Hello World

\n

Hello World

"; + + $view->render('extend'); + + $this->assertContains($expected, $view->render('extend')); + } + public function testRenderLayoutMakesDataAvailableToBoth() { $view = new View($this->config, $this->viewsDir, $this->loader);