SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Founder of Primal Skill Ltd. feketegy's Avatar
    Join Date
    Aug 2006
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Smarty Pros and Cons

    I'm considering using Smarty in my templates.

    What do you think? What are the pros and cons using specifically this templating engine?

    From my point of view it's important to be fast and not to be resource intensive.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like Smarty myself.

    Now, the only real con is that Smarty is not a full blown language, so for some tasks that I think wholly belongs in the view, like collapsing entries into groups with date headers, are harder to do in pure Smarty. Yeah, you can do them, but a programming language is better fit for programming (compared to a template language).

    Smarty has a {php} block, but I don't seem to be able to get variable accessing to really work. I always access Smarty's private variables with $this, though perhaps I've been doing something wrong.

    Otherwise, the only thing that matters is whether you prefer Smarty's syntax and system more. The rest (learning curve, performance, etc.) is moot. For me, I like Smarty over PHP because it has less distracting characters (like <, >, spaces and the like that conflict with HTML, even with syntax coloring) and I can do the same in less characters (so I can fit within line margins). The syntax is far easier on the eyes, IMO.

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Con - you're replacing PHP features (variables, loops, conditions) with Smarty features that do the same thing in most cases. In most cases I think using PHP as the template system makes more sense.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here's a pretty good summary of the PHP Templating debate.

    The upside of using PHP for templates...

    1. The full power of PHP is available
    2. No compiling
    3. Error reporting is handled by PHP
    4. No string parsing overhead
    5. No regular expression overhead (this can be pretty expensive)
    6. When using short tags, it actually looks like a template language.
    7. PHP is easy to learn for simple procedural things like loops and variable output.

    ...and the downside
    1. The full power of PHP is available (you might want to restrict access to the language)
    2. Output is immediate (this can be overcome with output buffering.)
    3. Templates need to be evaled if they reside in a database - making debugging difficult
    4. Template writers may need to be educated and learn some simple PHP
    5. There will be a temptation to put more than display logic in the templates
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot adam.jimenez's Avatar
    Join Date
    May 2009
    Location
    Ware, UK
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cranial-bore View Post
    Con - you're replacing PHP features (variables, loops, conditions) with Smarty features that do the same thing in most cases. In most cases I think using PHP as the template system makes more sense.
    Excatly, PHP is much better templating language then Smarty. PHP syntax is more familiar, I don't have to look out every strange constructs on the web.

    If someone wants to have a good templating language it should be very restricted, with no variable assignment (maybe no ifs) so it should not have any logic, it's just a view. But Smarty is just a PHP with different syntax, so what's the point in learning it?

    Have a look at StringTemplate, unfortunatelly it's not available in PHP.

  7. #7
    Founder of Primal Skill Ltd. feketegy's Avatar
    Join Date
    Aug 2006
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I myself is more of a using-PHP-in-templates fan, but I keep my options open and I wanted to consider Smarty.

    But I came to the conclusion that the functionality that Smarty offers, and the performance impact doesn't worth it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •