Skip to content

Commit

Permalink
Merge pull request #36 from vensko/master
Browse files Browse the repository at this point in the history
Default values for sections.
  • Loading branch information
reinink committed Oct 20, 2014
2 parents b30c77d + f0a801d commit 104cc53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Template/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Template/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ public function testStopSectionBeforeStarting()
$this->template->render();
}

public function testSectionDefaultValue()
{
vfsStream::create(array(
'template.php' => '<?php echo $this->section("test", "Default value") ?>'
));

$this->assertEquals($this->template->render(), 'Default value');
}

public function testNullSection()
{
vfsStream::create(
Expand Down

0 comments on commit 104cc53

Please sign in to comment.