diff --git a/src/Html/BlockBuilder.php b/src/Html/BlockBuilder.php index 575071ea7..9c2d03192 100644 --- a/src/Html/BlockBuilder.php +++ b/src/Html/BlockBuilder.php @@ -103,7 +103,7 @@ public function append(string $name, string $content): void * * If the block does not exist, then the `$default` content will be returned instead. */ - public function placeholder(string $name, string $default = ''): string + public function placeholder(string $name, string $default = null): ?string { $result = $this->get($name, $default); unset($this->blocks[$name]); @@ -120,7 +120,7 @@ public function placeholder(string $name, string $default = ''): string * * If the block does not exist, then the `$default` content will be returned instead. */ - public function get(string $name, string $default = ''): string + public function get(string $name, string $default = null): ?string { if (!isset($this->blocks[$name])) { return $default; diff --git a/tests/Html/BlockBuilderTest.php b/tests/Html/BlockBuilderTest.php index eede6e329..bcc0b28d4 100644 --- a/tests/Html/BlockBuilderTest.php +++ b/tests/Html/BlockBuilderTest.php @@ -229,4 +229,13 @@ public function testContainBetweenBlocks() ); $this->assertEquals('In between', $content); } + + public function testGetBlock() + { + $result = $this->Block->get('non-existent-block'); + $this->assertNull($result); + + $result = $this->Block->get('non-existent-block', 'default value'); + $this->assertEquals('default value', $result); + } }