SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Atlanta
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Includes | Reusable Page Elements

    What's goin' on-

    I'd like to `include` page elements within my documents. They would be the standard header, navigation and footer elements.

    But for the header, that would require my `title` and `meta` tags be set-up as variables for each new page.

    So where exactly do I put the information to fill those variables. On the .html page or the includes page?

    Is this the correct assumption? What are some other ways of going about this?

    Thanks for any help!

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I think I know what you mean. What I do is have two files top.inc.php and bottom.inc.php (.inc just tells me its an include file, has no importance).

    So top.inc.php would look like this:

    PHP Code:
    <?php
    function header($title){
    ?>
    <html>
    <head>
    <title><?php echo $title?></title>
    </head>
    // etc...
    <?php
    }
    ?>
    And the bottom.php would look like this:

    PHP Code:
    <?php
    function footer(){
    ?>
    </html>
    <?php
    }
    ?>
    Now in any page were I want that layout I do.

    PHP Code:
    <?php
    include 'top.inc.php';
    include 
    'bottom.inc.php';

    header('My title');

    // some code and more html output

    footer();
    ?>
    The reason I top and bottom have php extension and are called by a function is because otherwise people can view the entire source, not just the html.

    Hope you understand what I mean
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users


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
  •