Skip to content

Commit

Permalink
Default values for sections.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzmitry Vensko committed Oct 19, 2014
1 parent b30c77d commit f0a801d
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
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;

This comment has been minimized.

Copy link
@huglester

huglester Oct 20, 2014

can't we just return $default here?

This comment has been minimized.

Copy link
@baileylo

baileylo Oct 20, 2014

Contributor

👍

This comment has been minimized.

Copy link
@reinink

reinink Oct 20, 2014

Contributor

@huglester Good point, will fix.

}

Expand Down
9 changes: 9 additions & 0 deletions tests/Template/TemplateTest.php
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 f0a801d

Please sign in to comment.