Category: Smarty

Once upon a time there was Smarty!

With due respect to Monte Ohrt, Zmievski, Messju and those nice guys who contributed their time in Smarty.

I have used Smarty for a long time, even wrote a book on it and created a cheat sheet. But I think now its time to say there is no need to use an external template engine like smarty. With flexible view in MVC frameworks like CodeIgniter and CakePHP (Many others too) is there really any need to learn a separate template language like smarty? Once there was a time when people burnt their hand with RAW code and so called phrameworks and finally realized that they need something to separate the presentation layer from business. Some nice guys over there developed smarty and it saved life of a lot of developers (i mean developers). But that time is over. Seriously why the hell I need to learn a new templating language when a “echo” does the thing much better. Even smart frameworks come with some cool helper libraries where you will find helper functions to do some cool things that smarty’s date and time function does. I just dont need a wrapper over my PHP code which parse regular variable and echo them. Smarty just made itself extremely complex and useless too over the day, seriously.

I seriously don’t think there is need of Smarty anymore. Its dead! If you guys don’t agree with me, you can spend hell lot of time learning that {$name} actually does what you could do with “echo $name”. If you write a dispatcher which is smart enough to bring the variables from a controller scope to the scope of a view, why do u need to learn a separate parser like smarty? Moreover, of course it takes time in parsing the template files into equivalent PHP code and cost me some time. But hell no, I am not pointing to those microseconds I lost in extra parsing, I am pointing to the time I will spend learning smarty which is not needed at all. Learning all those functions, loops, logics, caching and others in smarty takes so much time that I would love to suggest you to learn writing efficient PHP code in template layer rather than learning something like smarty.

Update: Some of you commented that to keep designers away from PHP and to keep it safe, we should go for smarty. But is there really any designer who knows only smarty and no PHP? Is it really possible to write efficient code in smarty without knowing PHP? Nah, not at all. And there is {php} block which allow so called template designers to run unsafe PHP code inside it. Well, you can block executing {php} block from your side, but still smarty is not a solution to think that you are “secured”. And honestly, you should’t let your template designer write template code for you if they dont know PHP. And you should learn about XSS, SQL Injection and CSRF if you really want to live secured.

Sometime it’s better to realize thats its time to unlearn something.

Smarty Book has been published

Smarty PHP Template Programming and Applications My Book, “Smarty PHP Template Programming and Applications” has been published from packt publishers. I co authored this book with Joao Prado, Sr. software enginer from MySQL AB and Lucian Gheorghe, Sr. network engineer for Globtel Internet. It was really fun writing the book first time in my life.

David helped me a lot. But I remember that day when Damian forward my proposal to David. Without Damian, it may not be possible to start with packt. Rushav Sanghavi and Patricia Weir, My technical editors helped a lot to write something that useful. Especially Rushav spends a great amount of time to execute every code snippet.

I just remember a day when I was studying in seventh semester in RUET, where I graduated from, I was thinking if I can write a book internationally, one day…. . It was a dream to me. Thanks a lot to Packt Publishers for their co-operation. Kudos.