Who wants to have a template engine discussion? :)

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

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

Post 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 )
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

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

Post 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
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

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

Post 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.
Post Reply