Announcement

Collapse
No announcement yet.

An uncharacteristically newbish question from me

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • An uncharacteristically newbish question from me

    Hey there everyone,
    I'm an experienced PHP programmer who is just starting to delve into vB hacking. I've been picking apart the code and understand almost everything there is, except for the template system. I understand it's function and why things happen, but not quite how they happen. For example, I've been trying fruitlessly for the last 20 minutes to write a simple header/footer page with no content, and it just doesn't make sense to me. I'm sure that I'm just reading too hard into the problem, but I'm just vexed by everything, and I was wondering if someone could give me a little Templates 101 lesson? If someone could even write up the aforementioned header/footer page I'm sure that I could figure it out.

    I hate asking because it makes me sound so newbish, which I'm definately not (I'm actually the programming forum moderator at Somethingleet), but this is something that's just got me in a corner. I'm normally the one answering the questions, not asking them. I guess you've got to start somewhere!

    Also, I posted this on vB.org in hope of a speedy response. If you frown on posting to both forums then just go ahead and delete this thread.

    Thanks everyone for your help!
    Mystis

  • #2
    Use the forumhome template as a reference. Here is a template template :

    Code:
    {htmldoctype}
    <html>
    <head>
    	<title>$bbtitle - Page Title</title>
    	$headinclude
    </head>
    <body>
    $header
    
    
    
    $footer
    </body>
    </html>
    Content goes between the header and footer variables.

    Comment


    • #3
      Alright, this is coming together at last! I almost feel sheepish for not getting this. I've got this in file.php
      PHP Code:
      <?php
      error_reporting
      (7);
      require(
      'global.php');
      eval(
      "dooutput(\"".gettemplate('templatename')."\");"); 
      ?>
      And a template with your code in it named templatename. Waht really vexed me was how the header and footer were automatically added if you inserted a template. It makes MUCH more sense now.

      Thanks

      Comment


      • #4
        Alright, I've struggled this far:
        PHP Code:
        <?php
        error_reporting
        (7);
        require(
        'global.php');
        eval(
        "\$template_nav .= \"".gettemplate('template_nav')."\";");

        eval(
        "dooutput(\"".gettemplate('template')."\");"); 
        ?>
        and then the template 'template'
        Code:
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <html>
        <head>
         <title>$bbtitle - Page Title</title>
         $headinclude
        </head>
        <body>
        $header
        <br />
        $template_nav
        <br /><br />
        $footer
        </body>
        </html>
        And then template_nsv obviously being some navigation. What I'm really struggling with now is trying to set up database extracted data in the proper area. I can query the database alright, but I can't figure out how to output the data where I want it to go. Any pointers? Thanks!

        Comment


        • #5
          You need to assign data to variables, then you can use the variables in the templates for the page. Examples:

          This code gets the username and email address of the user with a userid of 1:
          PHP Code:
          $array $DB_site->query("SELECT username,email
              FROM user
              WHERE userid = 1
              "
          );

          $userinfo $DB_site->fetch_array($array); 
          You would then use $userinfo[username] and $userinfo[email] to display this information in your templates.

          For queries that return multiple rows of data, use a while loop:

          PHP Code:
          $array $DB_site->query("SELECT username,email
              FROM user
              WHERE userid IN ("
          5,8,10")
              "
          );

          while (
          $userinfo $DB_site->fetch_array($array)) {
              

          This code gets the usernames and email address for userids 5, 8, and 10. The first iteration of the while loop is for the first user, the second iteration is for the second user, etc. Use a dot operator in the while loop to append each loop's information to one variable, like a bit template:

          PHP Code:
          eval("\$variable .= \"".gettemplate("template_bit")."\";"); 
          This will call the template called template_bit, and replace the variables $userinfo[username] and $userinfo[email] with the information from the current loop. Then when the loop repeats the template is called again and appended to the end of $variable.

          For a single assignment (not in while loop), replace .= with =

          Comment

          Loading...
          Working...
          X