Re: Thoughts on Templates
Posted: Wed Jun 11, 2008 6:02 pm
First I wanted to address Mordreds three points:
#2 is not necessarily true. Reading a template and doing str_replace() is not that slow compared to include().
#3 can be dealt with by having blocks in the template.
The main place I do not use PHP templates is when an untrusted user can edit the content.
In general I don't think that there is one best solution for templating. Not for a whole site -- not even for a single page. I think you should be able to mix template engines within a single page as appropriate.
#1 can be dealt with if the template library has a call that will loop for you.Mordred wrote:Some problems are:
1. One must "manually" loop the loops and enumerate the vars to be replaced
2. Runtime string replacement is ... slow.
3. The template snippets are separated (assuming you'll read them from file or something), which, if one wants to change something, make it hard to identify in which piece a particular string resides.
#2 is not necessarily true. Reading a template and doing str_replace() is not that slow compared to include().
#3 can be dealt with by having blocks in the template.
My argument with this statement, which I agree with, is the idea the the template engine is the View. I think the template engine is sometimes the whole View, but the View can also simply use a template engine for part of its work.Everah wrote:Why would you want to add the extra processing logic of assigning/replacing variables/values? I thought, for a while, that a template engine was THE thing to do to separate business logic and presentation logic. I was totally wrong.
The main place I do not use PHP templates is when an untrusted user can edit the content.
In general I don't think that there is one best solution for templating. Not for a whole site -- not even for a single page. I think you should be able to mix template engines within a single page as appropriate.