To (PHP) third party template, or not to...

They have: 121 posts

Joined: Dec 2008

Using PHP, I'm still in the "But PHP IS a templating language" camp. This article does make some interesting arguments, however:
http://fabien.potencier.org/article/34/templating-engines-in-php

What do you think?
Cheers,
Shaggy.

He has: 629 posts

Joined: May 2007

Dunno. Depends on what you mean by "templating language," I think. For me, a template language would know about tags, elements, nodes, and attributes. It would be smart about the need to escape certain characters as entities. And so on.

But then, that article refers to a "template engine" - something that I'd expect to be data driven. That hardly applies to PHP. I think the author is confused. (And so am I...)

I'd think something like XSLT would qualify better as a template language. But what do I know...

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

He has: 629 posts

Joined: May 2007

Serendipitously I just came across this - The Twig Project "The flexible, fast, and secure template language for PHP."

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

(and no, using the more compact <?= shortcut is not an option)

Yes it is. I'm guessing that the author doesn't like that because it isn't enabled on all servers. So what? Just because a feature *might* not be on 99.9% of all PHP environments, they don't want to use it?

I can see both sides. I used to use TBS on all my projects exclusively because I had the idea that I would have a designer working with me one day. Well, the reality of it is that template engines do make projects more complex because it is like adding another programming language to the mix. Sure, you can display a variable with {{ var }} instead of <?=$var?>, but the author fails to mention the overhead of running a template engine compared to none at all, and the difference is significant.

Over the last year or two, I have used CodeIgniter for most of my projects. It only comes with a simple templating engine that I wouldn't recommend using unless you extend it or the project is simple. I got TBS working really well, but once I took a step back and saw all the code and effort it took to getting everything working, using the PHP short tags and alternative syntax seemed like a better alternative, so that's what I have done recently. In the end, the sites run much faster, and the template code still is manageable if done right.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.