Permalink
Browse files

Merge pull request #36 from vensko/master

Default values for sections.
  • Loading branch information...
2 parents b30c77d + f0a801d commit 104cc539320c082f16dd5e421ecc1039779e4526 @reinink reinink committed Oct 20, 2014
Showing with 17 additions and 3 deletions.
  1. +8 −3 src/Template/Template.php
  2. +9 −0 tests/Template/TemplateTest.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;
}
@@ -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(

0 comments on commit 104cc53

Please sign in to comment.