diff --git a/src/Template/Template.php b/src/Template/Template.php index 193c4bbe..53689d18 100644 --- a/src/Template/Template.php +++ b/src/Template/Template.php @@ -197,13 +197,18 @@ protected function stop() /** * Returns the content for a section block. - * @param string $name - * @return null + * @param string $name Section name + * @param string $default Default section content + * @return string|null */ - protected function section($name) + protected function section($name, $default = null) { if (!isset($this->sections[$name])) { + if (null !== $default) { + return $default; + } + return null; } diff --git a/tests/Template/TemplateTest.php b/tests/Template/TemplateTest.php index c9498b1c..bec24aa1 100644 --- a/tests/Template/TemplateTest.php +++ b/tests/Template/TemplateTest.php @@ -145,6 +145,15 @@ public function testStopSectionBeforeStarting() $this->template->render(); } + public function testSectionDefaultValue() + { + vfsStream::create(array( + 'template.php' => 'section("test", "Default value") ?>' + )); + + $this->assertEquals($this->template->render(), 'Default value'); + } + public function testNullSection() { vfsStream::create(