SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: saving time..

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, on the forum-skript of "bbhacks" I found a good way to save much time, but I did not really understood it. So they have one file called "include.php3" where the put all those informations which you need on every page such as "font" and "font size" and "bg colour" and so, and than they use this variables on every page. So you can easily change the font for all your pages, just by changing it on the include file (I'm sure this trick is not very new, but I didn't knew it before).
    But what I do not understand is, how they use PHP variables on there html pages. What they do looks like this here:

    include.php

    function style () {

    global $font, $small, $medium, $large;

    $font = "Arial...";
    $small = "1";
    $medium = "2";
    $large = "3";
    ....
    }

    and the html pages look like this:
    page.html
    ...<font face="$font" size="$medium">Hello</font>

    But as far as I know you can not put any php variables in a html page unless you say <?PHP echo ("$medium"); ?>, but they didn't do it like this. Any idea how this works?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They probably read the file in and then replace the vars with values and then print the page to the screen. I am not too familiar with how blazeboard works although I just installed it for a client, I haven't had a chance to dig into it. I will have a look at the code and let you know what I find.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! They use eval() to evaluate the code which in turn interpets the variables within the .html file. Example snippet :
    Code:
    $newline = template("foruminfo_form.html");
    eval("echo stripslashes(\"$newline\");");
    And template() is in include.php and it looks like this :
    Code:
    function template ($file) {
        return addslashes(implode("",file("templates/$file")));
    }
    Overall, I don't agree with this. eval() is an expensive function and doesn't need to be used for a template system. So imho, don't follow the blazeboard style of programming. As freddy suggests, search and replace is common for template systems. And regarding template systems, check out Smarty :

    http://www.phpinsider.com/php/code/Smarty/

  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)
    Philip,

    Smarty looks pretty cool, but I gotta say phplib's template class is the best as far as I have come accross. Everyone should ahve a look at it.

    http://netuse.phplib.de
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Philip, I think this is not my level, I understand nothing. And Freddy, anyway this link seems to be wrong, I get an error message.

  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)
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that link is working. But I just decided to keep on doing it "manual", as this looks just like chinese for me. Thanx, Alex

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm in the habit of simply using constants - I have a table called "constants" with three fields: constantid, constantname, and constantvalue - I use a while() loop in a site-wide file (global.php or something) to DEFINE() all of the constants.


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
  •