diff --git a/system/View/View.php b/system/View/View.php index 9a39104728df..842c9993414b 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -406,8 +406,11 @@ public function endSection() /** * Renders a section's contents. + * + * @param bool $saveData If true, saves data for subsequent calls, + * if false, cleans the data after displaying. */ - public function renderSection(string $sectionName) + public function renderSection(string $sectionName, bool $saveData = false) { if (! isset($this->sections[$sectionName])) { echo ''; @@ -417,7 +420,9 @@ public function renderSection(string $sectionName) foreach ($this->sections[$sectionName] as $key => $contents) { echo $contents; - unset($this->sections[$sectionName][$key]); + if ($saveData === false) { + unset($this->sections[$sectionName][$key]); + } } } diff --git a/tests/system/View/ViewTest.php b/tests/system/View/ViewTest.php index 537740231f66..61742d943984 100644 --- a/tests/system/View/ViewTest.php +++ b/tests/system/View/ViewTest.php @@ -387,4 +387,14 @@ public function testRenderNestedSections() $this->assertStringContainsString('
Second
', $content); $this->assertStringContainsString('Third
', $content); } + + public function testRenderSectionSavingData() + { + $view = new View($this->config, $this->viewsDir, $this->loader); + $expected = "Hello World
"; + + $view->setVar('pageTitle', 'Welcome to CodeIgniter 4!'); + $view->setVar('testString', 'Hello World'); + $this->assertStringContainsString($expected, $view->render('extend_reuse_section')); + } } diff --git a/tests/system/View/Views/extend_reuse_section.php b/tests/system/View/Views/extend_reuse_section.php new file mode 100644 index 000000000000..f7a5c0a263e2 --- /dev/null +++ b/tests/system/View/Views/extend_reuse_section.php @@ -0,0 +1,9 @@ += $this->extend('layout_welcome') ?> + += $this->section('page_title') ?> += $pageTitle ?> += $this->endSection() ?> + += $this->section('content') ?> += $testString ?> += $this->endSection() ?> diff --git a/tests/system/View/Views/layout_welcome.php b/tests/system/View/Views/layout_welcome.php new file mode 100644 index 000000000000..a3623a4aafad --- /dev/null +++ b/tests/system/View/Views/layout_welcome.php @@ -0,0 +1,3 @@ += $this->renderSection('content') ?>
diff --git a/user_guide_src/source/changelogs/index.rst b/user_guide_src/source/changelogs/index.rst index 9932e8725891..cdffd1cb94f0 100644 --- a/user_guide_src/source/changelogs/index.rst +++ b/user_guide_src/source/changelogs/index.rst @@ -12,6 +12,7 @@ See all the changes. .. toctree:: :titlesonly: + v4.4.0 v4.3.2 v4.3.1 v4.3.0 diff --git a/user_guide_src/source/changelogs/v4.4.0.rst b/user_guide_src/source/changelogs/v4.4.0.rst new file mode 100644 index 000000000000..6632a061c4d1 --- /dev/null +++ b/user_guide_src/source/changelogs/v4.4.0.rst @@ -0,0 +1,78 @@ +Version 4.4.0 +############# + +Release Date: Unreleased + +**4.4.0 release of CodeIgniter4** + +.. contents:: + :local: + :depth: 3 + +Highlights +********** + +- TBD + +BREAKING +******** + +Behavior Changes +================ + +Interface Changes +================= + +Method Signature Changes +======================== + +Enhancements +************ + +Commands +======== + +Testing +======= + +Database +======== + +Query Builder +------------- + +Forge +----- + +Others +------ + +Model +===== + +Libraries +========= + +Helpers and Functions +===================== + +Others +====== +- **View:** Added optional 2nd parameter ``$saveData`` on ``renderSection()`` to prevent from auto cleans the data after displaying. See :ref:`View Layouts