Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 2340694

Browse files
committed
Merge branch 'feature/133' into develop
Close #133
2 parents 5633881 + 5b29a15 commit 2340694

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ All notable changes to this project will be documented in this file, in reverse
1111

1212
### Changed
1313

14-
- Nothing.
14+
- [#133](https://github.com/zendframework/zend-view/pull/133) modifies the
15+
behavior the `placeholder()` helper to no longer render a prefix or postfix if
16+
no items are available in the container.
1517

1618
### Deprecated
1719

src/Helper/Placeholder/Container/AbstractContainer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ public function __toString()
113113
*/
114114
public function toString($indent = null)
115115
{
116-
$indent = ($indent !== null)
117-
? $this->getWhitespace($indent)
118-
: $this->getIndent();
116+
// If we don't have items - do not show prefix and postfix
117+
if (! count($this)) {
118+
return '';
119+
}
120+
121+
$indent = ($indent === null)
122+
? $this->getIndent()
123+
: $this->getWhitespace($indent);
119124

120125
$items = $this->getArrayCopy();
121126
$return = $indent

test/Helper/Placeholder/ContainerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,20 @@ public function testIndentationIsHonored()
432432
$this->assertContains(" <ul>\n", $string, $string);
433433
$this->assertContains("\n </ul>", $string, $string);
434434
}
435+
436+
/**
437+
* @see https://github.com/zendframework/zend-view/pull/133
438+
*/
439+
public function testNoPrefixOrPostfixAreRenderedIfNoItemsArePresentInTheContainer()
440+
{
441+
$this->container
442+
->setPrefix("<h1>")
443+
->setPostfix("</h1>");
444+
$string = $this->container->toString();
445+
$this->assertEquals('', $string);
446+
447+
$this->container->set('');
448+
$string = $this->container->toString();
449+
$this->assertEquals('<h1></h1>', $string);
450+
}
435451
}

0 commit comments

Comments
 (0)