Monday, June 9, 2008

Why Use Smarty?

 



I've used Smarty for like 4 months now. I don't know why I need to be using it anymore. I mean, it's redundant. PHP is a templating language -- it just needs to be used in a more organized way.

Doing things the Smarty way, you usually make your XHTML template, then insert Smarty tags. Unfortunately I've been making some hairy Smarty pages with too much business logic in them for if/then and loop, and I need to, instead, put that back in the PHP code and dump something ready to go into a section.

From the XHTML template with the Smarty tags, you then move to your PHP page, load your Smarty class, set some variables on that class, and then feed it the Smarty template page.

Well, if that's the case, why not eliminate Smarty and do it in PHP? You just get your XHTML template, insert your PHP tags as , save the file as a PHP file in your templates subfolder, and then merely build the PHP vars in your pages and, as the last thing you do, perform a require_once() to load the template which will then load in all the appropriate variables.

Why does this have to be so hard? It doesn't have to be.

Still, you should learn Smarty because, unfortunately, many clients still want you to use this because they didn't get the memo on PHP being an effective template language, already.

No comments: