revjim.net

August 9th, 2002:

Smarty: love/hate

Apparently Smarty (now at version 2.3.0) has been adopted by the folks at PHP.

I have a love/hate relationship with Smarty.

I’ve been using it for quite some time now. It is a wonderful method of separating layout from code. But it does much more than that. It allows you to separate layout logic from the code as well. Most templating engines wouldn’t even consider that. So even though they advertise the separation of code from layout, the minute the HTML designer wants to do anything more than change the colors or the graphics, a coder has to be called in. So now, separation of layout from code didn’t buy you much, except that now you have to edit two (or more) files, instead of one.

Smarty is easy to use, and easy to teach.

Smarty is easy to extend. Creating custom functions, modifiers, insertable chunks of code, and filters is a breeze for the moderately knowledgeable PHP programmer. Just learn a relatively simple API and the rest is easier than conning an alter boy into your private quarters for his penance.

And if you don’t see the value of separating your layout (and your layout code) from your application code, then you haven’t written very many large web applications.

Smarty just makes sense.

I know what you’re thinking now: “Then why, good Reverend, did you say you have a love/hate relationship with Smarty? What’s there to hate?”. Let me tell you.

The more one thinks about Smarty, the more one find himself inventing cool and novel ways that it could be used to do every day tasks. This is good. However, as you continue to think about these things, and perhaps start to implement them, to find yourself practically writing your own programming language, aimed at a specific task.

I could write enough Smarty extentions to allow VERY a very customizable weblogging system, or photo gallery in no time flat. If it were done correctly, all these Smarty componets could interact with one another making the customization possibilities even more endless. For instance, if I did write weblogging extentions and photo gallery extentions, it would be rather trivial to allow photo gallery items to be embedded into specific weblog entries.

Don’t worry. I’m there with you. You’re thinking, “But Reverend, these sound like amazing and wonderful things? I still don’t understand what there is to hate.”. Worry not, believer, I’m getting there.

The reason I hate Smarty is because it makes it too easy to make all these things happen, that now I want to be locked in a room for months with one other person (and an occasional conjugal visit) to do nothing but churn out amazing applications that will revolutionize the usability of the web for the common man, giving him powers he has never possessed before.

“But Reverend, that still sounds wonderful… amazing… truly grand. God would be so pleased with you. You would be pleased with you. The world would be pleased with you. Rich men would send you money. Newpapers would beg for photographs and Interviews. Supermodels would beg for your loins. Other people’s wives would yearn to have your children. Teenagers would write your name on their naked breasts as they showed the world via their webcams. WHY, OH WHY, WOULD YOU NOT WANT THIS?!?!”

It’s simple: Tech Support.

*shudder*