Page 4 of 4

Re: Who wants to have a template engine discussion? :)

Posted: Sat Jan 24, 2009 2:33 pm
by allspiritseve
The Ninja Space Goat wrote:When I allow them to just freely sprinkle php throughout my templates, I quickly end up with this:
Looks familiar... my boss codes like that.

As far as queries inside templates go... if you switched to PDO and didn't have an open mysql_* connection for them to use, that might encourage querying earlier (unless of course they make a new connection in the template just to query the db 8O )

Re: Who wants to have a template engine discussion? :)

Posted: Sat Jan 24, 2009 4:43 pm
by Eran
I don't like giving the ability to freely do whatever they want in the template. I much prefer the template engine in this case. Sure, when I'm doing projects on my own, it makes sense to just use php as the template engine. I think that's why I've always preferred not to use a template engine... because I worked by myself. Now I have to work with people who really have no clue about good practices, and I don't have the time to educate them. I have deadlines.
If you're using a template engine to protect your application from inept developers, that's fine. When you started this thread, you said you didn't understand why PHP developers cringe when templating system are brought up - I tried to give my opinions on that.

Fortunately for me, I am the boss at my company and can enforce the kind of standards I expect from my developers, so I have the liberty of working with PHP as the template engine.

Re: Who wants to have a template engine discussion? :)

Posted: Sat Jan 24, 2009 5:42 pm
by Christopher
pytrin wrote:If you're using a template engine to protect your application from inept developers, that's fine. When you started this thread, you said you didn't understand why PHP developers cringe when templating system are brought up - I tried to give my opinions on that.

Fortunately for me, I am the boss at my company and can enforce the kind of standards I expect from my developers, so I have the liberty of working with PHP as the template engine.
I agree that if there are no security concerns then PHP templates are hard to beat. I also use HTML templates for CMS use cases where I allow users to directly edit the content. For HTML templates I just use dumb but fast str_replace() templates. They are as fast has PHP templates. I just push to logic into a View class for those. And it's not hard to make various templates interchangeable.

Re: Who wants to have a template engine discussion? :)

Posted: Sat Jan 24, 2009 10:31 pm
by josh
Yep, if you trust your designers its probably better for both parties to use plain PHP, but if your designers are random vagrants from the interweb, you start to get 2nd thoughts 8O

Re: Who wants to have a template engine discussion? :)

Posted: Tue Feb 03, 2009 5:29 am
by Mordred
Sorry to join so late in the discussion :)

For me templates are:
1. Separation of HTML and PHP (subtly different than "presentation and logic", but nevermind that)
2. Higher-level and short way of doing the most repetitive things:
- conditionals
- displaying arrays of data
- forms

Of course everything is possible with PHP alone, the point is that:
- it gets ugly (whether you mix HTML in the PHP or PHP in your templates)
- it needs more typing
- you keep writing the same boring patterns (how do you output an html table from a 2d array of data or a collection of database rows?)

I might add that some of the template engines out there (I'm looking at you, Smarty) do a lot of work, while still not solving these problems

I've already mentioned my template engine (still not GPL, sorry) , and it was in a very similar thread here some half year ago. There was a nice showdown of several engines so we could compare results and code. A yes, here it is (also started by Ninja ;)): viewtopic.php?f=19&t=81806&st=0&sk=t&sd ... e&start=45
I have since had some more revelations about what more (and what less) it needs, just haven't had the opportunity for refactoring and features.