I think you can use views all the way.
For example:
<!-- email.phtml -->
Dear <?=$this->escape($this->firstName)?>
Thanks for registrering at <?=$this->siteName?>!
Cheers,
Webmaster
And in your controller, you'd do:
$this->view->assign('firstName', $firstName);
$this->view->assign('siteName', 'example');
$emailBody = $this->view->render('email');
// continue with Zend_Mail etc. here
Sure we can use Zend_View wherever we like. I was not worried about
that. But thanks anyway for the snippet.
Why does nobody mention the (in my eyes) horrible bug (it's
definitely not a
feature!) in PHP itself that was last discussed in 1998 and then
somehow
accepted by the community as a "feature": PHP eating newlines after
the
closing tag
http://brian.moonspot.net/php-history-newline-closing-tag
I think that is why people like to omit the closing tag.
Generally, there are ways to make it more pretty or to force a format.
Can you give a more detailed example as of where your problem is?
The XML output example on http://brian.moonspot.net/php-history-newline-closing-tag
was quite a good example.
It's just about complexity or ugliness of our view scripts. Here's my
emailBody example:
-----------------------------------------------------
<!-- email.tpl (Smarty) -->
Your address:
{if $title != 'Firma'}{$title}
{/if}{if $company != ''}{$company}
{/if}
{$firstname} {$lastname}
{if $special1 != ''}{$special1}
{/if}
{$address}
{if $pobox != ''}{$pobox}
{/if}
{if $country != ''}{$country}-{/if}{$zipcode} {$city}
Your access to the world:
username : {$username}
password : {$pw}
-----------------------------------------------------
<!-- email.phtml (Zend_View) -->
Your address:
<?php if ($this->title != 'Firma'): ?><?=$this->title?><?=PHP_EOL?><?
php endif; ?>
<?php if (!empty($this->company)): ?><?=$this->company?><?=PHP_EOL?><?
php endif; ?>
<?=$this->firstname?> <?=$this->lastname?><?=PHP_EOL?>
<?php if (!empty($this->special1)): ?><?=$this->special1?><?=PHP_EOL?
><?php endif; ?>
<?=$this->address?><?=PHP_EOL?>
<?php if (!empty($this->pobox)): ?><?=$this->pobox?><?=PHP_EOL?><?php
endif; ?>
<?php if (!empty($this->country)): ?><?=$this->country?>-<?php endif; ?
><?=$this->zipcode?> <?=$this->city?><?=PHP_EOL?>
Your access to the world:
username : <?=$this->username?><?=PHP_EOL?>
password : <?=$this->pw?><?=PHP_EOL?>
-----------------------------------------------------
See the difference?
Both are ugly in some way if I want to stick with this template style
full of opening and closing tags. But at least, in a Smarty-template
we can provide "real" newlines while they would get cut off by PHP's
closing tag in a regular PHP/Zend_View-template. Using PHP_EOL is just
an ugly workaround.
I don't understand exactly where they look messy. Details. ;-) Point
taken, HTML/PHP mixed doesn't look pretty -- then again, when people
use my website, they view it through a browser which renders it all
pretty and they don't have to look at the source code.
Right. But that's not the point. We are talking about what could make
our lives easier, the developers lives. The end user anyway gets a
nice and clean output served by us.
It would be really nice if PHP folks could provide us with an ini-
setting to turn off this (in my eyes) nasty behavior.
Cheers,
Philip