Sugar Developer Blog

Smarty or PHP as a templating language?

12 Feb, 2010
Posted By: John Mertic

Just came across an interesting post by Ibuildings CTO Ivo Jansch, talking about the use of Smarty as a templating language over PHP itself. His argument comes down to the the cleanliness of the code; he considers Smarty code much easier to read and follow when used inside a PHP script as compared to PHP itself.

SugarCRM uses Smarty extensively as a part of our metadata, themes, and MVC frameworks to help separate the markup from our PHP code, and have built in several optimizations to our use of Smarty to avoid some of the speed penalties from using it. What does everyone else think about using Smarty as a templating language? Sound off in the comments with your thoughts.

Tags: , , , ,

  • I have to agree with David on this, I've always felt the template engines should be used for parsing content, specifically.

    Adding in the additional fuss from a whole programming language just adds to the page load.

    Also, I feel like, in some cases, it can result in even more "unclean" code because of the way customizations may have to be done on certain modules or included objects.

    For example, I just customized the 'Datetimecombo' object adding the ability to set a default time. It was quite daunting to have to code between PHP, JavaScript, basic HTML, and the Smarty engine. I know for a fact that the solution I came up with was not as efficient or UI friendly as I would have hoped for.

    That's not to say Smarty is useless or doesn't work. Just feel it to be a bit too deep into the logic side of things, rather then focusing on better parsing procedures.
  • David Kelly
    I don't like Smarty. Adding conditions and logic into a template just adds a layer of complexity and makes the template engine run slower. I'd much rather Sugar had stuck with XTemplate and kept logic and HTML apart, and not required the annoying workarounds for Smarty's inability to handle escaping properly.
  • I do like Smarty and it's capabilities and I think Sugar made a Smart(y) move by choosing to use it. It would be nice to see all Xtemplate code and the Xtemplate library itself removed from the next major release.

    By the way, I found the examples used by Ivo Jansch to be a bit self-serving to fit his article. That PHP code could have been better.
blog comments powered by Disqus
Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.