SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    USA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    To Template or Not to Template, That is The Question!

    I've been reading about templates and how wonderful they are. Most examples offered to demonstrate their value depicts a situation where the html is done by one person and the php by another. I'm sure for that situation templates are of value but I do it all myself and from my view templates are just one more thing to learn and to have in the way. On the other hand I'm just learning php and might be to new to be able to appreciate the true value of templates. What is your feeling on this subject? Will PHP 5.0 be forcing templates on us or is that not an issue in this topic?

    Thanks for sharing your views with a newbie.

    RogerR

  2. #2

  3. #3
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My answer is that any serious PHP web application should keep PHP entirely seperate from HTML. There are some that argue that PHP itself is the best templating solution, and whilst in theory that may very well be correct, I feel that from a coders and designers point of view it simply makes more sense to use a templating system that involves a third party syntax. I use a very simple engine I devised myself, though not unlike a ton of them that exist out there.
    As you are a PHP newbie I will say that it may be best to walk before you can run and go with your natural instincts to mix PHP and HTML together so as you can understand the problem with doing this and then appreciate the solution of seperating them.
    I do believe that PHP5 has the smarty templating system bundled with it, though this does not mean in any way that it requires you to use that system or any.

  4. #4
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it depends on the project you are working on. I am definitly still in the process of learning and I discovered what 'templating' meant only a few days ago. Reading about Smarty made me think that I would definitly choose a template solution if one day I had to work on a big project involving various coders/designers etc. However, as long as I will be learning how to do things with php I won't use a template system simply because I am the only person involved in the creation of the pages. I can still handle the few php portions I have in the middle of XHTML tags. I noticed that moving to OO is a first step to get rid of the PHP code within your HTML code. In other words, templating will probably be one of the last steps in my learning trip. That is obviously just my $0.02 and my words should be taken for what they are.


  5. #5
    SitePoint Member
    Join Date
    Feb 2004
    Location
    USA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found myself very sympathetic with Vincent in his rant ( http://www.sitepoint.com/forums/show...7&postcount=15 ).
    He verbalized much of the feelings I've developed about the subject of templates but, being new PHP, don't have the confidence of my convictions for the simple reason that I just don't know the subject well enough to take a stand. I do believe, for the present time, that I'll not bother worrying about templates but rather concentrate on learning PHP. Maybe after I've become comfortable with it I'll start to understand a need for templates.

    Thank you Streetlife and Dangermouse for taking the time to answer a newbie's question. I really appreciate both responses.

    RogerR

  6. #6
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd go with templates, doesn't matter what you use though

    Mixing PHP with markup is fine as well, from a templating point of view, though provided that the PHP is reading only, such as an iterator for example, thus there is no business logic within the markup

    Another tip is what I do is to have a folder structure like this for example,

    Code:
    templates
    +-- xml
    +-- xhtml
    +-- smarty
    And then have a DEFINEd variable to specify which to use, such as

    PHP Code:
    define'TEMPLATES''/templates/xhtml' ); 
    That way I could for example, have this,

    PHP Code:
    ...
    $this -> template TEMPLATES.'/news.template.tpl';
    ... 
    To use XHTML, but I could easily use XML or Smarty later if I need to make a change, by changing only one variable.

    May sound pretty obvious but you'd be suprised the amount of people who miss this one out, and then need to make changes all over their files

    Note also, the file extension would remain constant for XHTML, XML, Smarty, et al - else what's the point of using the one variable


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
  •