SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why we should use template engine

    Hello,
    we are coding a major php application,
    but i fear, do we really need to use a template engine?

    what are the benefits?

    please explain.

    thanks in advance.

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please search.

    this was discussed 100,000 times before.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "please search."

    Really? Why even waste the time replying to him? If you can't be helpful, why even type it out? If he were to search and reply to a post from a year ago, you or someone else would complain about bringing up an old post...

    @success

    It depends on your skills as a developer, and the control you need over the project. Personally, I have never found the need for a template engine, but thats mainly because I have built, over the years, a 'system' of my own and see no reason to change it. Most of the template engines have an effect similar to that of VB or other simplified languages. You gain easier/quicker development and you lose control at the lower level.

    Every project is different. If you can afford the time, start with a template engine. Set some close goals, and work towards them with the idea of finding out as quickly as possible if any of the shortcomings of whatever template engine you use will hinder you.

    Also, if you're not entirely comfortable with php to a relatively high degree, a template engine may suit you better, as well.

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rjm1982 View Post
    "please search."

    Really? Why even waste the time replying to him? If you can't be helpful, why even type it out? If he were to search and reply to a post from a year ago, you or someone else would complain about bringing up an old post...
    Next time, please do read forum rules and sticky moderational posts before preaching others how to reply "properly".

    For your reference,
    http://www.sitepoint.com/forums/showthread.php?t=192980

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, good thing you're here to tell us all the rules. Maybe one day you might grow up to be a moderator.

    Until then, maybe you could let the forum work in the spirit it was intended to: to help people.

    by the way... I just checked the rules. No rule against asking a question that's already been asked and no rule saying you must search first.

    And the sticky you referenced. "strongly encourage" != "required". They encourage it because it makes it easier on the person to search. However, nowhere does it say its mandatory or required.

  6. #6
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you really want to help OP, please stop trolling around, search the forum on "php templates" or similar and post the links to the relevant threads here.

  7. #7
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't really matter if you use a template engine or not. What does matter is that you separate presentation from business logic, so that your presentation has no more than simple HTML output, PHP blocks echoing out variables, and using control structures. All the complicated logic, including database access, etc, should be separated out.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it may not apply to you, but if you're confident with php, and so is everyone else involved with development, then you could use the dom to generate your markup - then you wouldn't have to rely on markup at all. Using this method, I've ended up with varying degrees of PHP class representing different stages of logic - it actually works quite nicely.

  9. #9
    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)
    Quote Originally Posted by Jasper. View Post
    it may not apply to you, but if you're confident with php, and so is everyone else involved with development, then you could use the dom to generate your markup - then you wouldn't have to rely on markup at all. Using this method, I've ended up with varying degrees of PHP class representing different stages of logic - it actually works quite nicely.
    Did you ever come across a simple tutorial or article that switched you on to thinking of exploring that avenue? It sounds really interesting, I would like to know more, but with a gentle intro ... y''know?

    Off Topic:

    hang on, should I search first?

  10. #10
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post

    Off Topic:

    hang on, should I search first?
    well, if you feel comfortable looking stupid... no, you don't have to search before you post.

  11. #11
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jasper. View Post
    it may not apply to you, but if you're confident with php, and so is everyone else involved with development, then you could use the dom to generate your markup - then you wouldn't have to rely on markup at all. Using this method, I've ended up with varying degrees of PHP class representing different stages of logic - it actually works quite nicely.
    This sounds quite interesting. As I'm not too familiar with how to go about this (and thus can't search the forums, just to make other people happy ;D) do you have any links that give more information about this?

  12. #12
    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)
    Ahh, a soupcon too much irony there - sorry you didn't get it.

    No offence.

  13. #13
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm,
    thanks for the suggestions and good game going on here lol

    so now i want to stick with my php code only with no template engine

  14. #14
    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)
    PHPGuru's thoughts on template engines, and the following users comments might make a more insightful read though.

  15. #15
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I started to create a template engine and use it in the past and noticed it can cause the load time to increase on large sites. I recommend designing a site w/o creating your own engine or using one such as Smarty, and instead use includes. This is the approach I take and it works great. I include the top of my site which I usually save as template.top.php then after my content I include the bottom of my page template.bottom.php. This method works great for me b/c it doesn't really effect my load time and I can still easily make multiple templates. This is just my $0.02.
    Kayzio - We don't hesitate, we accelerate.

  16. #16
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    currently iam doing in that way only,
    but i heared template engine can load up things so i asked question.
    iam getting mix results.

  17. #17
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I have tried making my own template engine and use ones out their and from my experience the load time is longer with a template engine. I ran tests using FireBug in Firefox to test the speeds. When you think about it with a template engine the PHP has to parse the "template engine language" which is more complex on the backend and causes more load. For example in PHP you could do
    PHP Code:
    if($var="valid") {
    echo 
    "valid";
    }else {
    echo 
    "invalid";

    When in a template engine it may look something like this
    Code:
    {if var="valid"}
    valid
    {else}
    invalid
    {/if}
    which after being parse is read like the PHP above. So basically you are adding an extra step to the whole process. The only real reason I could see for a template engine is for really really inexperienced coders, or if you allow others to make the templates and want themn to have limited control with what they can do for example you dont want them to have access to sessions or you dont want to allow them to use exec();
    Kayzio - We don't hesitate, we accelerate.


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
  •