Line breaks and white lines of Zend layout.html output

905 Views Asked by At

As per the Zend Framework standard, I'm using Zend_Layout.

 zf create project demo
 cd demo
 zf enable layout

That's it

Here's my config:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

Here's the situation in layout.phtml:

<?= $this->doctype() ?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>  
      <?= $this->headMeta(); ?>


      <?= $this->headTitle(); ?>

    </head>

Outputs:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />      <title>Dashboard</title>       </head>

My problem is, all line breaks and white lines are removed. How can I get them back?

But, outputs of "echo $this->layout()->content" are ok(line breaks and white line still there).

2

There are 2 best solutions below

0
On

setIndent() , setPostfix() and not caring too much about the indenting and new lines seems to be the answer(don't like that though).

setIndetn() and setPostfix() are somewhat explained in their manual (the helpers inherit these methods from the class PlaceHolder);

Usage example (causing not-so-nice html-source/-code):

<?php echo $this->doctype(); ?>
<html>
<head>
<?php
echo $this->headMeta()->setIndent( '    ' )->setPostfix( "\n" );
echo $this->headTitle()->setIndent( '    ' )->setPostfix( "\n" );
# ...

for reference sake; among other pages, i read(parts of):

.

8
On
<?= $this->doctype() ?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>  
  <?= $this->headMeta(); ?>

  <?= $this->headTitle(); ?>

</head>

Just add empty line after view helpers.