[thelist] Re: PHP inside or outside?

Carl Meyer cjmeyer at npcc.net
Wed May 5 22:52:45 CDT 2004

On Mon, 3 May 2004, Douglas Livingstone wrote:
> http://www.sitepoint.com/article/beyond-template-engine/1
> This is an advocation of using a PHP based templating engine. The basic  
> idea is that it isn't "mixed code"which is the problem, but "mixing  
> application logic and presentation" is the problem; as you almost said  
> yourself.
> It basically says:
> {$var} is really  <?=$var;?>
> What do you think of this technique?
> For me it equates to the "PHP in XHTML" solution.

Agreed that the maintainability problem is mixing application logic and
presentation.  The big difference between a template engine and "PHP in
XHTML" is that the former forces you to separate logic and presentation[1] ,
whereas the latter is just a coding style - you can still very easily stick
all your business logic into little chunks of PHP scattered here and there
through your HTML.  It's very easy to write an unreadable mess of PHP and
HTML while very carefully keeping all your HTML outside of the little <? ?>

If, on the other hand, you do all your business logic first, and then
include an HTML file containing little PHP more complex than <?=$var;?>,
congratulations: you've just created a very basic template system.


[1] Well, mostly.  A really expressive templating language like Smarty's
gives you enough rope to hang yourself if you so choose, but it still
encourages separation.

More information about the thelist mailing list