ZF-6094: I would like to see PHP_EOL added to __toString() on standard view helpers
Description
When using "View Page Source" in a browser, if a standard view helper has been used, the line that follows the view helper's outputted code will be on the same line. When creating a layout.phtml file I will tend to put something like <?php echo $this->doctype() ?> on the first line, then the opening tag on the next line. But when viewing the source code in a browser, the tag appears immediately after the generated on the same line.
This is the same for many of the other view helpers I have used (e.g. headTitle and headMeta) which can make the generated code very messy for front end developers that rely on "View Source" to see the HTML. Therefore I would like to see PHP_EOL added to the end of the __toString() function for the view helpers so that any generated code will actually be outputted similar to that which was intended within a layout script.
I would also like another feature changed on some of the view helpers that spread their output onto multiple lines (e.g. headMeta and headLink). Currently if a indent is passed to the function e.g. <?php echo $this->headMeta()->setIndent(4) ?> then the indent is added to the beginning of each line that is outputted. As I like to put this initial indenting within my layout.phtml script so that my layout scripts try to follow the outputted source as closely as possible, this means that I can end up with the first line of, for example, the headMeta having an indent of 8 spaces which comprises of the four spaces I placed before my opening php tag for the headMeta function within my layout.phtml, and then the next lines of the meta output are displayed with 4 spaces. This means the code can look very messy when the source is viewed. I do not see the point in having the indent on the first line of the outputted source.Therefore I would like to see the indent removed from the first line but used on the subsequent lines.
I believe a simple fix for both of these issues can be achieved by changing the __toString() function to something like the following -
public function __toString()
{
return trim($this->toString()) . PHP_EOL;
}
as this could prevent both issues.
Comments
Posted by Gideon Cresswell (gideon303) on 2009-03-24T15:52:07.000+0000
Additional:
I've noticed that this would also be very useful on the layout() and render() functions too - and I presume (although not tested) that both partial() and partialLoop() probably also suffer from this issue.
Posted by Rob Allen (rob) on 2012-11-20T20:53:28.000+0000
Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".
Feel free to re-open and provide a patch if you want to fix this issue.