Anyone else dislikes SMARTY?

I never used smarty for my projects because I always felt that it was a needlessly complicated class that did not contribute anything useful but made you learn its syntax like it was another language without many additional benefits…

So, with cs-cart I was forced to read up on smarty so to be on the level. I still detest it.

My point is that smarty just adds cpu time but provides a little return.

Take for, while loops in smarty… Same thing as in php without any added benefit. Does its syntax help you shorten the code? No. Same amount of lines.

Sure, smarty is a step where you separate content from the data and logic but all you do is pass an array of values from one php file to another… Problem is, to work that array you got to write a weird code in a weird syntax while the same thing could have been done in PHP. Assemble your array, create another php file that inserts your values into html. Same thing but much simpler and not as CPU intensive.

I fail to see advantages to smarty, it does not make code any shorter but it makes it more weird and what for?

If you ask me, smarty is a fifth wheel, I detest its implementation and it is a single thing that I hate about cs-cart.

Well, I’ve been using Smarty template class for over 6 years.

Do I hate it? No.

Before that I was using PHPlib template class is the good old early days of PHP.

It’s intended to separate code from design, back in the days of HTML 3.

Was there a purpose? Yes. Is there still a purpose? Yes, but not as much as before. However, it’s still quite useful. Much easier to update one piece of code, then going into multiple templates of multiple skins to make the change.

Many frameworks have the own template class.

Someone on SMARTY forums posted a comparison and also questions the benefits:

[url]Smarty ::

The discussion of the benefits of Smarty have been going on for years. The bottom line is that for the foreseeable future, CS-Cart will be Smarty-based. Your choices are pretty obvious: move on to another cart which does not use Smarty or become as proficient as possible in its use. The third option is to campaign to have it dropped but this isn’t gonna happen any time soon.


I know of my choices, I am very realistic and truthful with myself regarding the unpleasant choices. However, I thought that maybe, maybe I can be proven wrong but I held my breath for too long and totally in vain.

[quote name=‘TexasGuy’]Someone on SMARTY forums posted a comparison and also questions the benefits:

[url]Smarty ::

Wow, those aren’t really good arguments for or against Smarty or any template engine.

That’s like arguing against CSS style sheets because I can hardcode styles right into the HTML template. :roll:

Just as CSS style sheets separates HTML code from presentation, a PHP template engine separates PHP code from presentation.

Just as CSS style sheets offer more flexibility over hard coding styles into HTML files, PHP template engines offer more flexibility over harding PHP code into HTML files.

If I want to change all my headers to a different font and color, I would just modify the CSS style sheet containing the class “header1” for example.

Same logic applies to Smarty template engine.

I would never create a Smarty template that looks like this:


{foreach $foo as $bar}





There were no rows found.



unless it’s being use to populate a placeholder.

It defeats the purpose of a template engine.

My template would look like this:



It’s a freaking placeholder. Pretend the placeholder is a class or element ID. I can insert the placeholder into hundreds of places in hundreds of templates.

If I want {$AWESOME_TABLE} to show something different in over 100 different locations, I just have to modify the code in one place.

Or be an idiot, and update the code on over 100 different HTML templates that contains:


{foreach $foo as $bar}





There were no rows found.



and change it to:


{foreach $foo as $bar}





Wow. I just wasted a hour updating over 100 templates containing this code.



Using a placeholder also allows me to use the templates with other scripting languages like PERL.

Maybe I needed to use PERL because it has modules I needed, but not available in PHP.

The other benefit of Smarty template engine was its caching/compiling ability. So the PHP code does not have the being parse and interpret over and over again. Not much of a big deal these days.

Seriously. I think you are just complaining because you have to learn something new.

I think most of the people who complain about template engines are new to PHP, so they feel less of a need for template engines such as Smarty.

Well, while I didn’t understand all of Hyteckit’s response, I did really like it.



Can’t you use functions or even ‘goto’ for this? It is not like PHP has no syntactical means to accomplish the same…

And, yes, it pisses me off to no end when I have to learn a technology I do not see the benefits of.

Smarty isn’t there to make any PHP developers life simpler. It’s there so your designer has a much simpler language to learn. Though in the long run, it’s probably better for them to learn a little PHP. If you’re already familiar with PHP, then it’s just as simple for you to go instead of {$var} .

I do believe it is incredibly important to keep logic from presentation, and while Smarty does force this, I don’t think it’s the best way to do it either. It’s just as simple with PHP alone. PHP started off as a template engine and grew into a full blown language. It’s still damn good at being a templating engine when used for that, without the burden of a second language to learn.

If you create helper classes in your boot strap, then you can easily call $widget->table($awesome) in your template. Then you simply have a class with whatever constructs you use often. And if you want you can extend it to make it more versatile , $widget->table($awesome, $options).

No matter what, PHP is more versitile as a straight up template engine rather than building another one on top of it. It’s just the Smarty forces a bad programmer to be a better programmer, or at least follow better practices. The programmer should learn how to do it without Smarty. But most PHP programmers start with spaghetti code, never have any formal programming training, and don’t know how to setup a boot strap. I can’t say I wasn’t there once (though I was a irc script kiddie and took CS1-3 in HS) but once I realized my ****ty ways, I quickly revised everything I did.

As far as it being in CS-Cart, I don’t really care. I already learned as much of it as I need, up to creating custom plugins and functions because of its limitations. But it is a waste.

Someone just needs to build a cart on top of a really good OOPHP MVC framework. Then I’d be happy. If I ever had time, I’d do it myself. Would only take like 1 month of 12hr days for me to recreate everything CS-Cart has in Yii.

-my 2c

Do I support the idea of a template engine - yes. Is that from my experience with Smarty - absolutely not.

I played with smarty years ago as it’s been around a long time. I find it’s methodology antiquated and when you start placing loops in templates how much are you really separating code and/or business logic from presentation?

I use cs-cart occasionally however I am primarily a Drupal developer and their PhpTemplate engine, in my humble opinion, far outshines Smarty on just about every level it’s supposed to be useful over using just PHP, and it’s easy (however I am quite experienced in Drupal so take that with a grain of salt).

When you need a little PHP in a Drupal template, you barely need a few snippets of code in a special file “template.php” (and on rare occasions perhaps other files) and as for the designer, unless they are doing a complicated design they can sometimes work exclusively in CSS and never have to touch the files with any PHP or HTML in them.

Although this is a bit of a simplification because we don’t live in a perfect world, the Drupal engine gets passed one huge object of objects and arrays and the whole thing gets rendered into HTML – no loops and almost zero logic in the templates.

The bottom line in my opinion is that Smarty is an old methodology that is overly complicated to learn and use and needs to be put out to pasture.

I also suspect there are other template engines out there that are similarly far easier to learn and use just from being newer and better thought through from the get-go.

This thread neatly reinforces the fact that cs-cart will always use smarty and there's no way around it.

As a person who knows how to be write php I think it's a bad choice: you can do everything that smarty does…in php…so why use smarty?

Is there any chance that we can NOT use smarty when writing our templates?

PS: I'm evaulating cs-cart and don't revel in the fact that I'm going to have to pay a designer to do what I would have been able to do if there were clean templates using php and css.

I particularly liked this quote:

[quote][color=#282828][font=arial, verdana, tahoma, sans-serif]Someone just needs to build a cart on top of a really good OOPHP MVC framework. Then I'd be happy. If I ever had time, I'd do it myself. Would only take like 1 month of 12hr days for me to recreate everything CS-Cart has…[/font][/color][/quote]

Maybe opencart will be it…

but cs-cart hasn't been superseded yet: it's still the most functionally complete package out there (without spending $1000's).

So, yay for everything cs-cart EXCEPT the template engine. which bites. badly.


I really don't like smarty templates I've been working with PHP for over 6 years, and used to embed my code into html.

But to be quiet honest its helpful for designers, easier to edit.

but as programmer I think PHP embedded into html is better.

For a custom website (single user or website) may be you don't need to use smarty templates,but for multi user open source code imagine that:

1- adding new skin or theme

2- adding new plug-ins or add-on

that means modifications in file and setting permissions.

full permissions for core files??!! - I don't think so, so in such works you need to set permissions for interface files only that means a separate from php code files, that leads you to use a template engine.


Ammar A. Al-Neamy


…but as programmer I think PHP embedded into html is better.


I don't like smarty either, but mixing php and html is a maintenance nightmare. If you're not using a full MVC framework try to create a view layer and a logic layer. Consider using Heredoc and to parse your logic results in the view layer.

Smarty is almost exclusively used for “control” (looping and conditional constructs). For that, it's quite good and reasonably effective.

However, there is so much business logic in the cs-cart templates that the concept of separation of the 3 basic application layers was lost long ago.

Use of associative arrays is a good match of PHP and makes creating useful data structures much easier and cleaner to work with.