SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Template Engines

    Hi, i have been developed a lot of small php websites over the last year using Smarty.

    I am now about to start working on a big project for myself and i am wondering if i actually should be using a template engine or not. Can you help me with the following questions

    1 - is the use of template engines seen as bad practice and unprofessional
    2 - do facebook, twitter, myspace etc use template engines
    3 - what is your opinion on smarty
    4 - what are the disadvantages of using template engines and or smarty

    Thanks in advance for your help...

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Here's my opinion:

    1 - No, using a decent template engine is seen as professional. It shows (an attempt at) seperating logic and presentation.
    2 - Probably, although I don't think they use an off-the-shelf templating solution, but their own engines.
    3 - Smarty is OK, although I personally find Dwoo and Twig to be cleaner in coding and faster in use.
    4 - The biggest disadvantage is that using a template engine causes a little overhead when generating pages. The extra overhead is negligable though, and the advantages (code cleanliness, readability) far outweighs the disadvantages.


  3. #3
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cool, thanks... very well put together... the reason i would like to use Smarty as it seems to be the most popular (correct me if i am wrong)

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    I think for any large project a template engine is a must - even if you use PHP as the template engine. This means you separate your presentation logic from the rest of your code.

    Good template engines will provide you with more nice stuff like template inheritance and many convenience functions helping to keep your html readable. I'd say the newest versions of Smarty are pefectly fine and there are others like Twig. The most important thing is not to abuse the template engine - don't put in them any logic that is not about presentation. Also, I've found out that the old Smarty-style of using templates is a big ugly and restricting: first assigning values to the template and then using them like {$var}, etc. I prefer to assign as little as possible to the templates and usually I assign a few objects from which my templates pull data depending on the needs.

    What's more - you should hang on here in this thread a little while - if you are lucky there are a few real Smarty haters in this forum ready to present their opinions . I'd say Smarty 3.1 is pretty good and performs quite fast. Just have a look at a few template engines and see which one you like best.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cool, thanks... waiting for the Smarty haters

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I'd say if you have taken the trouble to learn Smarty, stick with it.

    The only drawback I see with it is that it can do so many things you can sometimes be tempted to move some of the logic that should maybe be in your page controllers - in which case you could end up with what I call "fat templates".

    I really appreciated the hierarchical way you can build templates up though -- and much to my surprise I actually enjoyed working with Smarty for the first time this year.

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    I agree with what was said above. To add to it, I can tell you that facebook uses XHP, a custom rolled template engine that makes XML a first class citizen of PHP.
    I've been to talk about it from one of the guys from facebook and it looks pretty cool. Haven't done anything with it myself though.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •