Web Hosting Talk







View Full Version : To Smarty or not to Smarty?


jake712
06-16-2004, 12:07 AM
I'm in the process of making complex MySQL/PHP web sites and I'm coding my latest one using Smarty. Although I'm not a complete novice, I am building up my skills in PHP and its counterparts. Smarty seemed like a good decision at the time, but it seems to take significantly longer to code a site seperating content from logic. The obvious argument would be by doing this updating would be significantly easier, but there is overall more code and its spread out through directories, templates, and the core PHP files. How does everyone feel about Smarty? I think it's a great "plug-in" for PHP, but is the hassle and extra learning curve really gaining anything? Or is it just making it harder for everyone else to read your code and longer to type/alter?

Rich2k
06-16-2004, 04:37 AM
Personally I don't like smarty but it's quite powerful. I use my own custom tag system but it certainly isn't as powerful as that used in smarty.

webdesign jr
06-16-2004, 07:50 AM
And do not forget the server overhead. It should be significantly higher.


_____________________
webdesign & tvorba (http://www.scisoft.cz/webdesign-cz/webdesign.php)

This answer is not a guaranted true. Just a personal option of the God and myself.

shoperotic
06-16-2004, 09:22 AM
Smarty is NOT a template engine, is like a new 'pseudo- language', but very messy and with a bunch of problems, overloading the server is only one of those.
Try to learn a designer how to use Smarty, he will curse you ...
Cause Smarty is a template engine, so the designer will use it, not the programmer.
So if you want to use a real template engine, and complete separate the design from logic, use PHPLib or patTemplate, or a zillion of other real template engine, not Smarty.

jake712
06-16-2004, 12:07 PM
Originally posted by shoperotic
Try to learn a designer how to use Smarty, he will curse you ...
Cause Smarty is a template engine, so the designer will use it, not the programmer.

The programmer has to go through loopholes for the designer to even begin using it in the templates. I'm under the impression even if a designer wanted to look at the code, he/she would have to have a pretty good idea what's going on with the variables and actual code before diving in (and obviously Smarty "syntax"). I guess there are no Smarty fans on this board to give me the opposing arguments.

ambirex
06-16-2004, 12:08 PM
Smarty is a template engine. (which shoperotic says in the 4th line of his post) I say go ahead and use smarty, but try to build in such a way you could change template engines easily. I would also look into running MMCache or ionCube's PHP Accelerator with smarty. The combo of a compiling template engine with a good caching system can be a real benefit.

edit: I do lilke smarty it has plenty of good features and a fairly active forum, which is always a major plus when choosing a tool.

GoldenServ
06-16-2004, 05:49 PM
I always have my own classes (Templates, Core,Database,Configs) the templates class is inherted from Smarty
When I start programming a script, I just copy these four classes+ smarty.. and set the configs for links/urls/db name
And here I go

my class is easy to start with, just have to make folder called templates and put in file something like this
$Script->Templates->Assign("Var",$Value);
$Script->Templates->Load("main.tpl");

This makes smarty easy to deal with and doesn't take long time
I do sometimes use additional class which is Language, if I want to make it multi-langual script

If you did this stratigey , you will do it very fast
also, you don't have to desin the page in the template while you are coding
just assign the vars, and test it on the template by typing {$Var} and thats it, when you finish all what you want
start designing and putting the variables in their places :)

Oxygen_IT
06-16-2004, 07:50 PM
I like Smarty too much, you only need to know how to deal with it..

for me, I coded a special class named interface class, its only for dealing with Smarty, it makes using Smarty much easier to me..

However, I use Smarty only for big projects , for small projects, I use classic header and footer templates and CSS file

However, Smarty could make overload on servers, so use it only when needed.

nzbm
06-16-2004, 07:54 PM
Smarty is designed for large sites as Oxygeon_IT said. Using it in smaller sites could be overkill.

ckeeper
06-16-2004, 08:06 PM
well depend,
I use smarty since 1 year, and i never got any problem at all!
It even simplify my web site design update.
The big advantage is when your backend is finish, you dont need to touch to your php file when you need to do a update design and mess up with your stock.
Another one is you can take someone else to do the job. The only thing he need to learn is the smarty code that is "easy" to learn and he didn't have to mess with your code and maybe create a stupid bug like forgeting a ";"
I say "easy" because it can be hard to accomplish some task when you compare over pure php/html code.
It for sure that you have an overhead, even with cache option enable, but you have the choice. Having to modify your php/html (that can something be missing with all the stuff together) or have your code separate from your design..

luki
06-17-2004, 02:01 AM
Once you get used to it and understand it's strengths, Smarty will make your life easier. It's great for sites with multiple languages too -- all local specific info is in the templates (date formatting, currency and numbers).

For coding you can do this: in your PHP code make a variable called $out (for example) and add fields through the code that you want to provide to the template. Like: $out[order_date] = $row->order_date; and let Smarty handle the formatting. At the end of the code, tell smarty about this variable: $smarty->assign($out). Then you can write your own plugins and modifiers to help you out as well.

As for overhead -- it really isn't all that great. That's because each template is parsed only once per change, and the resulting PHP code for outputting the page is stored. Together with a caching system such as MMCache (as mentioned above) the combo is quite good and scales quite well.

But as with anything in the world, you can mis-use it and produce overkill templates that kill the server. For small sites, the setup is hardly worth the trouble though.

nexcess.net
06-18-2004, 01:34 PM
Smarty is a godsend. It makes templating easy and has a rich syntax that turns templates into simple scripts themselves. Whether you agree with this or not is up to you but from experience it's proven itself in our shop. Smarty is *not* too heavy for the smaller sites as it saves time in the dev process there too, and can make re-skinning your site simple.

Chris