Link Details

Link 266603 thumbnail
User 430852 avatar

By rick888
via rawseo.com
Published: Oct 22 2009 / 09:03

Comments

Add your comment
User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

Smarty is not a must have tool. In fact, it is a must avoid tool.

User 430852 avatar

Justin Silverton replied ago:

1 votes Vote down Vote up Reply

"Smarty is not a must have tool. In fact, it is a must avoid tool."

I disagree. What problems do you have with smarty?

I have used it on many projects and it has worked out very well. It allows you to separate all of your php code from designers/people that just want to make some html changes. It also has built-in caching, which makes it fast.

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

I have a problem with almost all of Smarty... The caching is nice I guess, but not worth all of the extra hassle that Smarty provides:

No proper syntax highlighting (there are some editors that do it sort of kind of mostly...)
It uses (by default) { and } causing all kinds of havoc if you have to embed some css or html (not that I do that a lot)
New syntax for common things that are already part of php
It is, however not a complete implementation of php, so trying to do certain things does not work
The array syntax is horrible, and sometimes you can use [ ], but most of the time you will use .
By default functions in smarty do not accept a whole array (which is because of the way that it was written, yes there is $array|@function)
The syntax to call a function is backwards from that of php: {$var|function}
Unless you are in an if statement: function($var)
If statements fail when you write them the way that you would normally in php: {if($something)} should be {if $something}
The 'section' loop
No while loop
No switch
The compiled php files that come out of smarty are worse than useless
As are the error messages (because they reference the compiled file rather than the template)
var in shorthand and value is in long hand in the assign function: {assign var=something value='some value'}
...
and so on and so forth...

User 430852 avatar

Justin Silverton replied ago:

0 votes Vote down Vote up Reply

I have a problem with almost all of Smarty... The caching is nice I guess, but not worth all of the extra hassle that Smarty provides:

"No proper syntax highlighting (there are some editors that do it sort of kind of mostly...)"

I don't think of it as a programming language. I use it as a template language, which works well with designers since they can open up the template files in a regular html editor.

"It uses (by default) { and } causing all kinds of havoc if you have to embed some css or html (not that I do that a lot)"

Surround all offending code with {literal}{/literal} and it will fix this issue.

"New syntax for common things that are already part of php"

This may be true, but I think it makes it easier for designers.

"It is, however not a complete implementation of php, so trying to do certain things does not work
The array syntax is horrible, and sometimes you can use [ ], but most of the time you will use .
By default functions in smarty do not accept a whole array (which is because of the way that it was written, yes there is $array|@function)

The syntax to call a function is backwards from that of php: {$var|function}
Unless you are in an if statement: function($var)
If statements fail when you write them the way that you would normally in php: {if($something)} should be {if $something}"

To each his own. I don't have problems with this syntax.

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

"I don't think of it as a programming language. I use it as a template language, which works well with designers since they can open up the template files in a regular html editor. "

The problem is that it has most of the constructs of a programming language, so programmers end up using it as a programming language causing all sorts of horrible code in the templates. Which is not easier for the designers.

"This may be true, but I think it makes it easier for designers. "

The designers that I know have found it harder, because they have to now learn 2 extra languages php and smarty just to be able to modify the templates.

"Surround all offending code with {literal}{/literal} and it will fix this issue. "

I know that, but that is just something they added to solve a problem that they created. Also, since javascript uses the {} syntax for objects you have to comment it out so it becomes: /*{literal}*/ /*{/literal}*/ just so that your syntax highlighter does not mistake it for javascript.
Causing things like this:


/*{literal}*/
...
var test = /*{/literal}*/"{$something}";/*{literal}*/
...
/*{/literal}*/

just so you can tell if the problem lies in your javascript code while you are writing it.

User 430852 avatar

Justin Silverton replied ago:

0 votes Vote down Vote up Reply

okay, what do you use instead of smarty?

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

php, since it is a template language already.

User 430852 avatar

Justin Silverton replied ago:

0 votes Vote down Vote up Reply

"php, since it is a template language already."

I figured this much from your previous comments. Every project I have worked on (many open source and many non-open source) that had no template language used (smarty..or anything else) was a complete nightmare to maintain.

You really should be using some sort of a templating engine...for the sake of the people that have to look at your code after you leave.

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

You can make an unmaintainable mess out of any templating language (engine). From what I have had to deal with, it seems that Smarty makes it easier when you don't know what you are doing.

User 430852 avatar

Justin Silverton replied ago:

-1 votes Vote down Vote up Reply

"You can make an unmaintainable mess out of any templating language (engine). From what I have had to deal with, it seems that Smarty makes it easier when you don't know what you are doing."

I find it funny that you mention that people that use smarty "don't know what they are doing". You essentially have to learn another syntax and language, which takes more skill than just intermixing php and html.

Show me an example of an html page, which has php and html mixed, that you think looks good (easy for a designer to read and easy to maintain in the future).

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply
User 430852 avatar

Justin Silverton replied ago:

0 votes Vote down Vote up Reply

Oh, and your example above? You could solve this issue by putting your Javascript code in separate files. It's better to do this for maintainability (you won't be able to re-use it without duplicating it) and the browser won't cache it (which will load faster if cached).

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

I realise that, but if other javascript code (or css) has been dropped into a template file and it uses variables that are only available in the template file, or because someone was too lazy to write a separate js file 4 years ago and it has been that way (and growing larger since then).

User 430852 avatar

Justin Silverton replied ago:

0 votes Vote down Vote up Reply

I know what you mean. I have had to work with legacy code like this and it's frustrating.

User 209773 avatar

SeanJA replied ago:

0 votes Vote down Vote up Reply

---- doh

User 463886 avatar

Christopher Strosser replied ago:

0 votes Vote down Vote up Reply

A little more effort could have gone into this... there are already too many "articles" w/ hundreds of "must-have" tools.

If it were my list, I would have limited it to the products I *REALLY* believe in... Eclipse PDT, FileZilla, PuTTY, OpenOffice, phpMyAdmin, Zend Framework, Crimson/Emerald Editor (simple, but powerful, not being actively developed), cPanel for server administration, WAMP or Zend Server for Windows development/staging... memcached, APC, or eAccelerator for caching.

....and so on and so forth.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.