View Full Version : Why use a templating engine?

08-07-2007, 10:55 AM

It just seems pointless... If your doing websites where your both the designer and the owner.

It's no fun, and you don't learn as much either.

08-07-2007, 12:49 PM
If you mean Smarty, there are lot's of reasons to use it. But if you are still new to OOP in PHP, then using template engines will not help you to improve your skills. Also smarty is not simple for beginner developers, and it's wrong to think that newbies use it. Most developers use Smarty only when they are sure in their OOP, and when they created few of their own template engines, and now can see why smarty is, as lot's of them say, a best way around...

08-07-2007, 03:45 PM
They allow you to segregate your php (processing code) from your html (output formatting code), making it faster and easier to maintain both. Also, they allow you more flexibility if working with a team - ie: the web designer needs to know little about php.

08-08-2007, 05:08 AM
Initially this is also what I thought. I recently began using smarty and while I am no expert here are a few benefits I rather like:

1) It is easier to focus on the code on the programming side without having lots of html in your line of sight

2) If you start dealing with lots of different Web sites you can easily pull components from one Web site and use them on another

3) You can avoid spam indexers by using {mailto} function and still display an email on a Web page. Crawlers can't understand the email, but normal Web browsers display it in human readable format.

There probably are other reasons, but I find some benefit with Smarty.

08-08-2007, 04:11 PM
My take on smarty or similar, template based systems, is that all the advantages are on coder's side, very little for the designer's side.

The majority of designers tend to use gui programs and wysiwyg html editors. Try throwing a smarty template into DW and watch it croak. Templating systems make the php developer's job easier and the designer's job a sh!tload harder.

Smarty syntax and markup looks no less confusing to a designer than php does. In fact, when things like image, css and js paths are tied up in smarty code, the whole layout goes to hell in any editor.

Ever since I started php coding, I have always practiced keeping php as separate as possible from the html. In one of the studios where I work atm, none of the designers have any complaints about my php/html pages since all the pages render fine in their editor of choice.

When a project involving smarty comes along, guess who gets lumped with converting flat image files to html? Not the designers; one look at smarty and they jump ship.

The exception to my generality about designers are hand coding designers who spend a lot of their time in code view. They tend to understand what's going on a lot better and develop tactics to overcome smarty's penchant for buggering up paths to external media.

08-08-2007, 05:32 PM
While I agree that templating engines do present their own challenges. But in my experience, these can be overcome with a little careful project planning.

True, smarty templates (and others, of course) don't play well with any wysiwyg design view that I've seen.

However, I have found designers that understand smarty (no doubt, the hand-coding variety). But also, I have worked with the strictly wysiwyg type of designer as well. Even in those case, it streamlined the development process by allowing the designer to dummy-up the pages. True, I was left to "smarty-ize" the template, but I would have been slicing up their design and inserting into my php anyway.

That said, templating engines are most certainly not a solution for everyone, but one in which I find more benefits than pitfalls.

08-08-2007, 05:52 PM
One surpremo advantage of smarty, despite my above post, is skins and caching. Templating systems are hard to beat for speeding up html output and user selected skins. The OO overhead of using smarty may be contradictory for performance in smaller sites; but for serverside resource heavy sites, smarty template caching is a treat.

08-08-2007, 06:56 PM

Yes, I use always a template engine no matter if I am the designar and the programmer at the same time, and no matter if my project is small or big.

I agree that its not easy for beginners, and when I teach php in my classes I first begin with the php tag, but for professional projects I always do the effort so I will gain in maintainability.

I love xtemplate. I dont like smarty but I not against the people who use it.

I wrote an article about it in my blog. Its here: http://socialviva.com/index.php?idSelected=1&action=viewBlog&comid=1&blogid=6&lang=en

Thanks and have a good php time :thumbsup: