SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what's the fastest and best template system which you prefere ?

    hello,

    please advice me the what is the fast and the best template system to use in my programmes ? smarty or templatepower or ،.... etc

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Pure and raw php...with helpers of course.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Pure and raw php...with helpers of course.
    Agreed. Don't use a templating engine, they don't actually achieve anything. Just use php.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    Agreed. Don't use a templating engine, they don't actually achieve anything. Just use php.
    Have you ever used a templating engine?

    To say they "don't actually achieve anything" is inane. They definitely achieve something - a separation of presentation and logic.

    With a templating engine, your script must pass all of its 'content' information created through logic functions to the templating engine. The designer can then take the raw information and fill out the presentation aspect of the page with html and the content values.

    It might be a valid argument to say they are inefficient or redundant, but they definitely accomplish something. They increase the abstraction of an application, so that each task in the whole project can be done independent of the other.

    To say that they do nothing is like saying that abstracting your applications into classes "does nothing." It may not be necessary, and it may be argue-able when they are appropriate... but they definitely serve a legitimate purpose.

    - Walkere

  5. #5
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Walkere View Post
    Have you ever used a templating engine?

    To say they "don't actually achieve anything" is inane. They definitely achieve something - a separation of presentation and logic.
    Not really, all they do is place the same information 1 step further away. I have used templating engines extensively, at work, and they don't do anything like this. Just because you put the html inside a page with php, doesn't mean suddenly all your business logic is there. You still keep the business logic in the classes and helper functions, and the php that displays the page just simply makes use of those.

    So no, a templating engine doesn't separate presentation and logic at all, that can easily be done with php too.

    Also, as wonshikee pointed out, there is usually just as much logic in a template as there is in php anyway. You HAVE to put logic in a template, it is completely impossible to separate them entirely.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    So no, a templating engine doesn't separate presentation and logic at all, that can easily be done with php too.
    You just refuted your own point. You said, "that can easily be done with php too."

    Like I said, it can be debatable whether or not a templating engine is efficient. To some people, it may not be worth the extra level of abstraction.

    However they clearly achieve a goal. That goal may be achievable with PHP as well, but that doesn't mean that a templating engine doesn't achieve that goal.

    My point isn't that PHP can't be used as a solution, or that templating engines are the best solution. They are, however, a viable solution. It may be arguable whether or not they are efficient, but to say they do nothing is inane.

    - Walkere

  7. #7
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    Agreed. Don't use a templating engine, they don't actually achieve anything. Just use php.
    That's incorrect. Templating engines like Smarty serve the purpose of keeping PHP out of your templates which serves three specific goals.

    1. Security. By keeping the templates free of potentially damaging PHP it becomes safe to allow untrusted parties to edit or create their own templates/themes.

    2. Usability. By restricting templates to a series of simple commands (and not trying to re-invent various PHP constructs as Smarty does) the templates can be made easy to use for people unaccustomed to programming such as designers.

    3. Consistency. By enforcing a particular interface for template development you can ensure that templates are developed in a consistent manner, avoiding the temptation of using quick hacks to resolve problems, something that's always a concern when developing in a team.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Richard Bone View Post
    That's incorrect. Templating engines like Smarty serve the purpose of keeping PHP out of your templates which serves three specific goals.

    1. Security. By keeping the templates free of potentially damaging PHP it becomes safe to allow untrusted parties to edit or create their own templates/themes.
    It is just as easy to cause a problem with a template as it is with php - it does have the logic in after all. I don't think it adds any more security than normal.

    Quote Originally Posted by Richard Bone View Post
    2. Usability. By restricting templates to a series of simple commands (and not trying to re-invent various PHP constructs as Smarty does) the templates can be made easy to use for people unaccustomed to programming such as designers.
    Most designers aren't as incompetent as you make them out to be :P The problem can easily be solved by hiring designers who are willing to learn new things / aren't idiots. Using PHP really isn't that big a step from a smarty template, just a different syntax.

    Quote Originally Posted by Richard Bone View Post
    3. Consistency. By enforcing a particular interface for template development you can ensure that templates are developed in a consistent manner, avoiding the temptation of using quick hacks to resolve problems, something that's always a concern when developing in a team.
    I have never found that 'not using a template' equates to 'willing to use small hacks' - I don't see the logic here? It is just as easy to develop consistently with php.

    What I HAVE found though, is that using templates means the php behind the view is usually quite untidy - people think it doesn't matter how it looks because they are under the impression that it is abstracted away from you. I have seen this several times.

  9. #9
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    It is just as easy to cause a problem with a template as it is with php - it does have the logic in after all. I don't think it adds any more security than normal.
    I tend to disagree. Unless you're going to completely disable all potentially damaging operations (file system access and database access minimum) when you reach your templates, PHP will always be a much higher security risk in the hands of untrusted parties.
    Quote Originally Posted by Stormrider View Post
    Most designers aren't as incompetent as you make them out to be :P The problem can easily be solved by hiring designers who are willing to learn new things / aren't idiots. Using PHP really isn't that big a step from a smarty template, just a different syntax.
    I think that largely depends on how we're talking about using your template engine.

    If you're going to take the Smarty route and use its reinvented PHP syntax then I'd agree with you. However I tend to think that's a pretty poor example of a template engine. What I like to use is more like the following:
    HTML Code:
    <helper:authenticated>
         <p>You're logged in!</p>
    </helper:authenticated>
    <helper:notauthenticated>
         <p>You're not logged in!</p>
    </helper:notauthenticated>
    No messy if statements, just xml tags with a well defined purpose that can easily be understood at a glance.

    Quote Originally Posted by Stormrider View Post
    I have never found that 'not using a template' equates to 'willing to use small hacks' - I don't see the logic here? It is just as easy to develop consistently with php.
    As a lone developer I'd agree with you; but consider a team working together. While you'd always hope that all would adhere to the proper standards, in reality that's not always going to be the case. Sometimes you'll hire new people who inevitably aren't familiar with your standards, or a developer might be running behind schedule and cut corners with the soothing promises of that devil on their shoulder telling them they'll clean that up later.

  10. #10
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Pure and raw php...with helpers of course.
    He's right!
    There are some things you shouldn't try to code at home.

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jason4Ever View Post
    hello,

    please advice me the what is the fast and the best template system to use in my programmes ? smarty or templatepower or ،.... etc
    I've only used Smarty for templating, so I couldn't compare it to anything.

    However, I quite liked it. Seemed fast enough and it was easy to learn.

    - Walkere

  12. #12
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've used Smarty and pears html_template_it. Smarty has a lot of very useful features but does involve using some logic (loops etc). Pears html_template_it does a better job of extracting logic from structure and uses a notion of blocks to create iterable chunks of code.

    Smarty has the best features and is probably faster due to it's template caching system but html_template_it is much more simple and more elegant.

  13. #13
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You can achieve the same thing as template engines using pure PHP.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  14. #14
    SitePoint Evangelist catweasel's Avatar
    Join Date
    Apr 2007
    Location
    Goldfields, VIC, Australia
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One doesn't need a template engine to seperate presentation from logic. Template engines are generally used when there is a nerd developing the back end and a arty designer coding the front end.. Smarty makes it easier on the designer by trimming down the geeky code as much as possible. Short tags were supposed to do the same thing.

  15. #15
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by catweasel View Post
    Smarty makes it easier on the designer by trimming down the geeky code as much as possible.
    Geeky code?

    PHP Code:
    <?php
    if ($var == $var2) {
        echo 
    $var 2;
    }
    ?>
    Code:
    {if $var eq var2} 
        {$var2}
    {/if}
    
    OR
    
    {if $var == var2} 
        {$var2}
    {/if}
    I disagree that somehow Smarty makes the code "understandable" for a designer and PHP code's equivalent is obscure and difficult to learn and a waste of time.

  16. #16
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't agree that a templating engine 'doesn't do anything'....when i look at a templated php file, without all the structual html in there things are so much easier to work with......and things are'nt always quite as drastic as wonshikee suggested.

    Each to his own i suppose

  17. #17
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by elduderino View Post
    and things are'nt always quite as drastic as wonshikee suggested.
    The example I showed is far from drastic if you ever looked at what Smarty offers.

  18. #18
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    In my opinion, they don't. Noone has managed to convince me otherwise yet either...

  19. #19
    SitePoint Member
    Join Date
    Feb 2008
    Location
    webrehash.com
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer to just use php just because it's simpler and I don't have to learn someone else's code to implement. Looked at Smarty once, but never used it.

  20. #20
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    And...My choice of editor/IDE colors PHP in my HTML...it doesn't for smarty tags.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  21. #21
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Why are you giving your templates to untrusted parties for anyways? o.O
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  22. #22
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I was answering that third point from the perspective of working in a team. I work in a team with a templating system at work, and it just doesn't happen.

    Also, given your example, I fail to see what is wrong with this:

    PHP Code:
    if ($objCurrentUser->isLoggedIn()) {
     echo 
    "     <p>You're logged in!</p>";
    } else {
     echo 
    "     <p>You're not logged in!</p>";
    }
    //if 
    It reads pretty much like English, easy to understand what is going on!

    I just don't see the point in moving all your html out of where it was, putting placeholders for data, then moving all the data into the placeholders and bringing the html back. Seems like a complete waste of effort to me, and I see no advantage to it - both at work and developing things by myself.


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
  •