Post by i2Paq » Sun Feb 06, 2011 7:09 pm

SMARTY sucks BIGTIME!

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by SapporoGuy » Sun Feb 06, 2011 10:30 pm

Smarty has always been known to suck ;)

note: refresh of this page will result in different times ... it seems that the test is live.
http://www.raintpl.com/PHP-Template-Engines-Speed-Test/
and
http://gonzalo123.wordpress.com/2011/01 ... omparison/

This rain template engine is not all that bad and haanga is smarty alternative.

(Please correct me if I'm wrong that opencart uses it's own template engine.)

I'd be interested in seeing how much overhead would be added or reduced by tweeking or replacing the current opencart template engine. So, which sucks more?

Smarty and other template engines uses their own code syntax however, django does too and I've seen very little complaining about that.

Is there a benefit to going to a template syntax?
As a coder - no since you can just drop in your php tags.
Is it simpler? no, because you have to learn the syntax.
They why?
Because, it is a syntax that designers can use and are used to.

But php is a template engine!
To be honest, where did the heck does that come from?
P = personal
H = home
P = page
.. = tools
Personal Home Page Tools ...PHP/fi
Which was just a bunch of cgi perl scripts to act like SSI insertions and made life much easier than working with perl which really is a pain when you insert stuff from outside files like a calling a function or class, well back in the day it was.

At the moment Perl6 and PHP6 are gaining the same reputation. As Larry Wall would say, it will happen when it is ready.

But this bit about php is a template engine is moot since opencart is using one ;)

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by Qphoria » Sun Feb 06, 2011 10:47 pm

- Daniel likes to keep as much as possible in-house
- Native php is more powerful
- Native php is faster
- a template engine is just another language to learn

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by SapporoGuy » Sun Feb 06, 2011 11:08 pm

I took the liberty to number these, thought it would be easier to respond.
Qphoria wrote: 1- Daniel likes to keep as much as possible in-house
2- Native php is more powerful
3- Native php is faster
4- a template engine is just another language to learn
1.) I have noticed that. Merits and Demerits on that. Unless Daniel is the super all around jock, and does the Bo Jackson. I'd say that sometimes it is better to go 3rd party.

IF that were to be true then why did he write, "I can make the page controller us the template class. Using that method means you can swap in and out the template class with the smarty one." ?

2.) Well, yeah ;)

3.) Not entirely true. Cache and hardware play a large share in this.
native php loses to rain tpl and is not much faster than haanga.
Here's a link that adds pure php to the mix
http://gonzalo123.wordpress.com/2011/01 ... plain-php/

I do agree that Native PHP is faster but opencart is using a template engine ala Daniel.

4.) Yep, I did state that too. But it is just a syntax and carries between projects. So, if opencart did use smarty or django syntax people will come in with less to learn than they will now.


The reason I'm interested in this is that there is always room for improvement and benefits that could be gained by going with a 3rd party solution. Take a look at the myriad of projects that do ;)

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by Qphoria » Sun Feb 06, 2011 11:22 pm

SapporoGuy wrote: 4.) Yep, I did state that too. But it is just a syntax and carries between projects. So, if opencart did use smarty or django syntax people will come in with less to learn than they will now.
But that assumes they already know smarty.. I looked at smarty... to me it was more complex than normal php. If a person can learn smarty they can learn php

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Xsecrets » Sun Feb 06, 2011 11:36 pm

where do you keep getting the idea that opencart uses a template engine? It does not. the files may end with .tpl, but there is no additional processing going on to allow for different types of tags or to convert anything into php. The only thing opencart does is export the data array and include the .tpl file.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by SapporoGuy » Sun Feb 06, 2011 11:49 pm

2 files:
system/engine/controller.php
system/library/template.php

Semantics, which is causing our different view points.
I am not saying that opencart uses any type of template engine syntax. I am just saying that it has a template engine albiet very simple in terms of functionality.

Or am I wrong?

Now compared to rain, rain just offers a few syntax codes while Haanga or smarty goes way way into template engine land.

Although ... Using a template engine as in smarty or other is not for everybody, it does offer a wide scale appeal compared to your typical I need xyz function because I'm selling twiggy wiggies.

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by Qphoria » Mon Feb 07, 2011 12:03 am

That is the reason right there..

Smarty, django, rain, haanga.... template engines are like opinions...
template engines are a dime-a-dozen... They all have one thing in common... they all run on php and php is already a template engine... so the most common point is where we look

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by SapporoGuy » Mon Feb 07, 2011 12:15 am

Lot's of people on the web say this but I haven't figured out where it is coming from. I did post above about what PHP was originally (I even doubled checked what I had remembered with wikipedia).

So, I still don't get this php is a template engine unless you mean that perl and python are template engines too?

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by marc_cole » Mon Feb 07, 2011 12:24 am

Qphoria wrote:Smarty, django, rain, haanga.... template engines are like opinions...
That's why I suggested something like PHPTAL in another thread. It's not just an opinion. It has one big advantage over the others and that's that it uses XML style placeholders so that designers can see what their page will actually look like without having to know PHP or without having to install OC on a server just to test their work.

Something like this would open the door to more designers than we could shake a stick at, which can only be a good thing for OC. Personally, I hate being forced to code my HTML by hand. I wish I could use Dreamweaver to design my templates for OC, but it's useless because all I see in design view is a blank page with some PHP graphic tags where the code is.

I don't know why, but as a group, we seem to be so opposed to something like this. Sure, PHP is fantastic! I can hardly put the book down that I'm reading. But it's not good for "designing" HTML pages. Why not use the right tool for the job? When building a house, you use a hammer. But how long would it take to paint the house with that hammer? (Alright, that's probably not the best metaphor, but hey... it's still early here ;) )

I really hope that the powers-that-be reconsider their position on this and implement a way to make it easier to design with graphic apps like Dreamweaver.

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by Qphoria » Mon Feb 07, 2011 12:45 am

well i dont know anything about any template engines... but someone did add smarty to zencart.. perhaps it can be done with only editing the controller and template files as a 3rd party mod. I just know that there are no plans to add it from the core perspective.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Xsecrets » Mon Feb 07, 2011 12:57 am

well I can almost see the point with phptal, though the argument that the designer would not have to learn php is rather stupid as they would have to learn phptal which will be every bit as hard as learning php. This is the problem I have will most all the templating engines you have to learn another language for no good reason. Like Q mentioned earlier I actually find the smarty syntax more confusing than php's syntax. I will admit though that something like phptal would help designers as they can get a visual representation of their design with sample data, but other than that I see no reason for having a template engine.

as far as the tepmplate.php being a template engine have a look into it it's a very short file and as I said all it does is extract the data array and include the .tpl file which will then get interpreted as straight php with no translation neededed.

Sapporo seems like your big concern is caching you've been pounding the forums in every possible way looking for some way to do more caching, but there is no need to add an extra translation layer just to get caching. Besides opencart is fairly efficient and most of the stuff that would be a big problem is cached. Do you have a client that is running a fortune 500 site on it or something where complete caching would really make that much of a difference?

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by SapporoGuy » Mon Feb 07, 2011 1:06 am

That is why I used this thread, smarty does already work to some extent work. Although it uses the old layout controller. Possibly some problems ... And all templates need editing.

You could offer a controller switch to use the current way or template engine.

I do recommend rain for simple TE and haanga or twig since you can change tags.

I'm still on the fence for phptal ... Would like to see comparison speed numbers and cache integration.


Pounding the forums???
A few post here and there, on topic, no tangents ... And you consider that pounding the forums?
Oh please!

As for caching, some other people might also be interested in speed and performance beyond what we get now. Besides with more jquery happening, a few microseconds might help.

930sc ... because it is fun!


User avatar
Active Member

Posts

Joined
Mon Nov 01, 2010 7:29 pm

Post by Xsecrets » Mon Feb 07, 2011 1:13 am

well I have no idea of speed on phptal, but as I said it's the only one I see that offers any real advantage for anyone, because at least it lets the visual developers see stuff. The only other one I can see any real argument for is smarty since it's unfortunately been used alot you do have several people who know it, though to be honest most of them probably know php as well. All the rest are just another language to learn that is more confusing than php so why bother.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by marc_cole » Mon Feb 07, 2011 2:06 am

Xsecrets wrote:well I have no idea of speed on phptal...
I'm going to get more info on this, but here's what the PHPTAL web site says:
PHPTAL is fast thanks to compiled templates and fine-grained caching. Makes it easy to generate well-formed XML/XHTML (protected against XSS attacks). PHPTAL's code is mature and improving. Released free under LGPL.
Also, if anyone is interested, here's a good write up on it from a graphic designer's perspective:
http://inside.webfactory.de/en/blog/tem ... hings.html

OpenCart v1.4.9.4
VQMod | Categories Home | Cleaner By Default - 2 Column | Speak Good English


Active Member

Posts

Joined
Tue Dec 14, 2010 11:26 am
Location - Seattle, WA

Post by JNeuhoff » Mon Feb 07, 2011 2:57 am

Qphoria wrote:
SapporoGuy wrote: 4.) Yep, I did state that too. But it is just a syntax and carries between projects. So, if opencart did use smarty or django syntax people will come in with less to learn than they will now.
But that assumes they already know smarty.. I looked at smarty... to me it was more complex than normal php. If a person can learn smarty they can learn php
Would be interesting to know whether there are any serious disadvantages or limitations to using Smarty as opposed to the OpenCart templates. E.g. could it really translate something as simple like this into Smarty:

Code: Select all

		<?php if ($logged) { ?>
		<a href="<?php echo str_replace('&', '&', $logout); ?>" class="button" style="text-decoration:none;"><span><?php echo $button_logout; ?></span></a>
		<a href="<?php echo str_replace('&', '&', $account); ?>" class="button" style="float:right;text-decoration:none;"><span><?php echo $button_account; ?></span></a>
		<?php } ?>
Or something like this:

Code: Select all

			<div id="navigation">
				<?php echo file_get_contents( HTTP_SERVER.'index.php?route=common/menus&logged='.$logged ); ?>
			</div>
Admittedly,the last example is not a good coding practice, calling a controller from a template to generate bits and pieces of HTML, though it helped avoiding the need to change core OpenCart files.

One of the advantages of Smarty is language independence, e.g. it could be used in C-sharp, Java servlets, and others, if I remember it correctly. But for the OpenCart software I don't see the point of adding pieces of code written in other languages to the system. And in real life, we'd end up mixing PHP with Smarty in the templates in quite a few places.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Xsecrets » Mon Feb 07, 2011 3:08 am

Don't really see what either of those code snippets have to do with smarty they are both pure php.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by JNeuhoff » Mon Feb 07, 2011 5:18 am

Xsecrets wrote:Don't really see what either of those code snippets have to do with smarty they are both pure php.
Well, OpenCart templates usually aren't pure XHTML, they frequently contain embedded PHP sections, for displaying variables, or for conditional statements or loops. Smarty is supposed to be able to do all of this using its own non-PHP syntax, if I remember correctly.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Xsecrets » Mon Feb 07, 2011 5:36 am

yes that's why I was confused if it was smarty it would be using the smarty syntax which is the whole reason I don't care for smarty since it's just one more thing to learn and basically does the same thing as php it can handle loops and conditionals, but using it's own confusing syntax.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by mkvirtanen » Thu Mar 31, 2011 8:40 pm

JNeuhoff wrote:
E.g. could it really translate something as simple like this into Smarty:

Code: Select all

<?php if ($logged) { ?>
<a href="<?php echo str_replace('&', '&', $logout); ?>" class="button" style="text-decoration:none;"><span><?php echo $button_logout; ?></span></a>
<a href="<?php echo str_replace('&', '&', $account); ?>" class="button" style="float:right;text-decoration:none;"><span><?php echo $button_account; ?></span></a>
<?php } ?>
From the top of my head:

Code: Select all

<a href="{$logout|escape}" class="button" style="text-decoration:none;"><span>{$button_logout}</span>
<a href="{$account|escape}" class="button" style="float:right;text-decoration:none;"><span>{$button_account}</span></a>
There has been a lot of talk about Smarty templates being "slow". All templates are compiled to PHP code each time they are modified and one can even turn off compilation check (=file modification check) to achieve a small bit of extra performance.

Here is another fragment from the address.tpl just for fun

Code: Select all

{$header}{$column_left}{$column_right}
<div id="content">
  <div class="top">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center">
      <h1>{$heading_title}</h1>
    </div>
  </div>
   ... lines removed here...
          {foreach from=$addresses item=address)}
			  {if ($address.address_id == $default)}
				  <tr>
					<td width="1"><input type="radio" name="address_id" 
						value="{$address.address_id}" id="address_id[{$address.address_id}]" 
						checked="checked" style="margin: 0px;" /></td>
					<td><label for="address_id[{$address.address_id}]" 
						style="cursor: pointer;">{$address.address}</label>
					</td>
				  </tr>
			  {else}
				  <tr>
					<td width="1"><input type="radio" name="address_id" 
						value="{$address.address_id}" 
						id="address_id[{$address.address_id']" 
						style="margin: 0px;" />
					</td>
					<td><label for="address_id[{$address.address_id}]" 
						style="cursor: pointer;">{$address.address}</label>
					</td>
				  </tr>
			  {/if}
          {/foreach}
Yes, there is a new syntax to be learned. It took me four hours to learn it eight years ago. After that I have seen no reason not to use Smarty for any purposes. My company has been involved in the creation of 300+ web applications for my customers, some of them small, some rather large. All of them make use of OO and Smarty templates. All of them. Most of them are simple, based on the database framework of our company but some are a bit larger, having dozens of modules and 60-80 database tables.

Well, there are other engines available like Open Power Templates and Twig, just to mention two "compiling" ones.
Twig has just been started, OPT has been around for some time and Smarty for ages.

Markku

Newbie

Posts

Joined
Thu Mar 31, 2011 8:17 pm
Who is online

Users browsing this forum: No registered users and 8 guests