Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use smarty template engine with MVC like Yii?

I used smarty in past, in x-cart, jobberbase and jomestate component of Joomla and some other Joomla components as well. I saw that things were very much tightly coupled in x-cart and many things seems to be more complicated than they should be in jobberbase and I had impression that this was because of smarty.

Now I am going to use Yii in a project, suggested by client. And Yii itself is MVC framework. So should I use smarty with it? I want to know that should I use smarty for it , I mean will there be some pros of using smarty in Yii? Or not? Or will it be just an overhead or will there be some cons of using smarty in it? I have understanding of smarty. But I think that is sometimes make things more complex. So I want to know from you guys, that is is just a dominant thought due to bad frameworks or there is some reality in that, so should I use smarty or is there some thing else better than that?

like image 697
Hafiz Avatar asked Apr 20 '12 21:04

Hafiz


2 Answers

As someone that used to use smarty before Yii I'd say there is no point.

Smarty was great because it prevented you from mixing logic and view in one file. MVC architecture defines that controllers (containing logic) and view should be separate anyway. I'd recommend that you write your views like you would in smarty templates, but just use php syntax. If you are using a good IDE (like netbeans) it will automatically indent your code too (see code formatting in netbeans).

Also have a look at Alternative syntax for control structures

Possible Opinion Of Yii creator

Yii itself is derived from Prado which is Qiang Xue previous project. Prado has a tempting language and Yii (out of the box) doesn't I'd assume that this means that Qiang believes a templating language is unnecessary.

Smarty Overhead

Smarty templates are complied to PHP once per change (if caching is enabled), this means that most of the overhead only happens for the first request, but I'd assume there is still some overhead in the extra function calls to check that the compiled view exists and this would affect every request. So there is an overhead to smarty, but it's probably negligible.

like image 120
Olly Hicks Avatar answered Oct 15 '22 02:10

Olly Hicks


Smarty is, like any template language, an expensive overhead.

As Rasmus Lerdorf said, PHP is already a template engine. Is there any reason to add another language with other controls structures, that you already have in PHP ?

Templates engines are only useful because they embed the cache logic. If you are not able to build a cache logic yourself, then learn it.

like image 21
Denis TRUFFAUT Avatar answered Oct 15 '22 00:10

Denis TRUFFAUT