Skip to content

Commit 104cc53

Browse files
committed
Merge pull request #36 from vensko/master
Default values for sections.
2 parents b30c77d + f0a801d commit 104cc53

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Template/Template.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,18 @@ protected function stop()
197197

198198
/**
199199
* Returns the content for a section block.
200-
* @param string $name
201-
* @return null
200+
* @param string $name Section name
201+
* @param string $default Default section content
202+
* @return string|null
202203
*/
203-
protected function section($name)
204+
protected function section($name, $default = null)
204205
{
205206
if (!isset($this->sections[$name])) {
206207

208+
if (null !== $default) {
209+
return $default;
210+
}
211+
207212
return null;
208213
}
209214

tests/Template/TemplateTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ public function testStopSectionBeforeStarting()
145145
$this->template->render();
146146
}
147147

148+
public function testSectionDefaultValue()
149+
{
150+
vfsStream::create(array(
151+
'template.php' => '<?php echo $this->section("test", "Default value") ?>'
152+
));
153+
154+
$this->assertEquals($this->template->render(), 'Default value');
155+
}
156+
148157
public function testNullSection()
149158
{
150159
vfsStream::create(

0 commit comments

Comments
 (0)