SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Templates?

  1. #1
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I hear a lot of talk about templates, and how it's better than using php to include files or using SSI, it also sounds more flexible and easy to maintain and customise.

    However... I have no idea what these templates are could somebody please point me towards a tutorial on the subject or give some info on the basic concept.

    Cheers

  2. #2
    Gong!
    Join Date
    May 2000
    Location
    Helsinki, Finland
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Templates are basically a layout of your website.

    --

    Edit: Big chunks of nonsense deleted (the facts left ). Thankfully freddydoesphp sorted the thing out the way it should have been done in the first place.

    And I really should learn how to read "I hear a lot of talk about templates, and how it's better than using php to include files --" the bolded worded instead thinking that it would be the word to.

    Enough of gibberish from my mouth
    Last edited by hmahonen; Apr 23, 2001 at 14:10.
    HighCheats - game cheats, codes, tips and tricks for PC and various console platforms

  3. #3
    I'm a college yuppie now! sbdi's Avatar
    Join Date
    Jul 2000
    Location
    Dublin , Ireland
    Posts
    1,271
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the only real problem with templates is if you use software like dreamweaver, it will mess it up big time your better off getting allaire homesite its very good
    Back Again

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you all are confusing Templates with simple server side including oh header and footer files. Templates are actually chunks of html code with placeholders in it, then you use a template engine like FastTemplate or PHPLIB's tempalte class to define and use the templates. For instance you have a user admin page that has something like
    PHP Code:
    //Contents of templatefile.ihtml
    <table>
    <
    tr>
    <
    td>Name:</td>
    <
    td>{name}</td>
    </
    tr>
    </
    table
    So you could use a template engine to read in the template and fill in the labels with data from somewhere and then print it to the screen. To do this with PHPLIB something like this

    PHP Code:
    include("template.inc");
    $t = new Template;
    $t->set_file("template_handle","templatefile.ihtml");
    $t->set_var("name""Bob Smith");
    $t->pparse("out""template_handle"); 

    Which wold produce the following html

    PHP Code:
    <table>
    <
    tr>
    <
    td>Name:</td>
    <
    td>Bob Smith</td>
    </
    tr>
    </
    table
    This is a very simple and crude example of what can be accomplished with the templates.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    <font>This is a very simple and crude example of what can be accomplished with the templates.</font>
    I have managed to grasp the concept of SSI (though I haven't put it into practise yet!) but this is what I really need to know about I think! Am I right in thinking that with a template, I can create a table that sets the look of each of the pages in a website and if I make any changes to the table in the template, it automatically updates every page?

    Can you tell me more please, or direct me to a tutorial or two??!! Thanks
    Saz: Naturally Blonde, Naturally Dizzy!
    No longer Editor of the Community Crier.

    Don't mind me, I'm having a BLONDE moment!

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes in theory, but don't forget, if you don't need to substitue any of the templates placeholders with variables, you don't need templates, and simple php includes will be fine. And yes with includes you can simply change the html in the included file and get it changed instantly on every page that includes the files.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot freddy I thought it would be something like that what with the way the VBulletin templates work, but I didn't know how to actually go about doing anything at all. I pretty much understood your example, but, as you said, it's not too in depth, just a small plea, if anybody has read any good tutorials on the subject then please link us there, or something. Or does the php manual cover it at all?

    Thanks again people.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for those.....I've added them to my favourites to read through later!
    Saz: Naturally Blonde, Naturally Dizzy!
    No longer Editor of the Community Crier.

    Don't mind me, I'm having a BLONDE moment!

  10. #10
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another advantage of templates is that, as you can see from freddy's code, they seperate the display (the HTML) and the application logic (the PHP) into seperate files. So a designer can be given the template tags to use in the HTML, and the programmer can go about creating the script that generates those values. Even if both these tasks are handled by the same person, the site is far more maintainable because you can muck about with the HTML without fearing that you will mess up the PHP and vice-versa.

  11. #11
    Bimbo With A Brain! silver trophy Saz's Avatar
    Join Date
    Mar 2001
    Location
    Kent, United Kingdom
    Posts
    5,275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh Boy, do I have a lot to learn!!!

    I think I'm going to have to make up a 'to learn' list and work through it all one by one!!!
    Saz: Naturally Blonde, Naturally Dizzy!
    No longer Editor of the Community Crier.

    Don't mind me, I'm having a BLONDE moment!

  12. #12
    SitePoint Addict SLeon's Avatar
    Join Date
    Sep 2000
    Location
    Northern California
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or if you wanted to go at this from the client side, you could do it with CSS. I just recently did my site with CSS setting the layout and the content in html files. Very cool. If you want more info, read Julian's recent article--it's still on the front page, I think, called "HTML Utopia."
    InformationSavant - developing intelligent web business
    StrangePegs.com - collectible cards, games, toys, comics

  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SLeon,

    hmmm... I still don't think you can achieve this with css on the client side. Maybe you are mistaken at what is trying to be achieved, templates need to be parsed on the server side not the client side. CSS is great for making your site look nice, but it does not help in this situation we are talking about templates that can take in data and be displayed not css rendering of your site.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for those links freddy, I too have bookmarked them all, I shall look over them later today.

    These forums seem very friendly, and everyone is willing to help everyone else. I like them very much

  15. #15
    SitePoint Addict SLeon's Avatar
    Join Date
    Sep 2000
    Location
    Northern California
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can create a table that sets the look of each of the pages in a website and if I make any changes to the table in the template, it automatically updates every page?
    freddydoesphp, this is what I was responding to. You can do exactly this with CSS alone, no need for a database. In CSS2, using the box model, you define the areas on the page--colors, locations, relationships to other areas, all kinds of formatting that can be done with CSS. Then you format your .html or .shtml document with "div" sections that either contain the data you want displayed or have SSI calls to other files for data. When the resulting page is displayed, it looks just like a normal page. And when you change the CSS file, all the pages that use that CSS are changed.

    Like I said, this was all recently in an article by Julian Carroll called "HTML Utopia," which is still on the SitePoint front page. Link is here: http://www.webmasterbase.com/article.php/379

    I find CSS a really exciting way to do this. And probably it's a much more accessible technique for a new webmaster with little design and no database experience.

    And again, my site http://www.informationsavant.com is completely designed with CSS. There are no tables at all, where before there were layers of nested tables. Cut my html file sizes down by 50%, too
    InformationSavant - developing intelligent web business
    StrangePegs.com - collectible cards, games, toys, comics

  16. #16
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh I totally hear ya, I use css positioning to do a number of things, but really you are controlling the look and feel not the content or data, even with SSI, your included page is static, I think the purpose of this thread and the goal of DarkMonkey, is a way to dump data to a page from a db for instance without having to handcode all the html, this is where templates come into play, your templates can certianly use css to layout the html, but the cool part is where you can fill the template with dynamic data on the fly, and this is what sets it apart from traditional SSI.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •