In Dreamweaver, you can create a template that will contain the header, footer, and links. If you have a 50-page site and you need to modify the header, footer, or links, you just make your change on the template and all the pages associated with the template will be updated. Under ASP.NET, the Master Page accomplishes the same. Is there such an animal with PHP?

To clarify, here's what I'm looking for:
[INDENT]1) A template/Master Page under PHP which contains the header, footer, and links. I guess you can also call this page the shell or layout of the site.

2) For the sake of this post, let's say I'm going to have a 50-page static site; I will not be using a database, maybe later, but not now. Each page will have it's own content (content1.php - content50.php).

3) I want to build the content pages separately, but apply the template/Master Page to them.[/INDENT]

If someone can direct me to an online tutorial, or post an example on how to do this, I'd greatly appreciate it. Just to let you know, I think I know what has to be done, but something is not clicking for me. So, when you post your code, please make it very simple for us that are struggling, and in unison we will probably smack our foreheads and say, "Damn, could of had a V-8!!!"

Thanks in advance for your help!

    There is no such thing in php; however, there are 2 functions you can use to simulate that.

    [man]include/man and [man]require/man.

    Include will continue processing the page even if the file isn't there or readable; while require will fail if the file isn't there or readable.

    So an example of this would be:

    template.php

    <!DOCTYPE html>
    <html>
        <head>
            <title><?php echo $title; ?></title>
        </head>
        <body>
            <?php echo $content; ?>
        </body>
    </html>

    contentX.php

    <?php
    
    $title = 'Something';
    
    $content = <<HTML
        <h1>Title</h1>
        <h2>Sub Title</h2>
        <p>Some static text</p>
    HTML;
    
    require('template.php');

    You can get more elaborate and use something like Smarty, but it's based on the same principle of including certain files at different points.

      I typically use a function approach, defining one for each "boiler plate" portion of the page. Then each page require()'s the file that defines those functions, and then calls them as needed. A simple example:

      template.php:

      <?php
      function head($title)
      {
         $html = "<html>
      <head><title>" . htmlspecialchars($title) . "</title></head>
      <body>
      ";
         return $html;
      }
      
      function foot()
      {
         $html = "<p>Copyright 2005 - " . date('Y') . "</p>
      </body>
      </html>";
         return $html;
      }
      

      any_page.php:

      <?php
      require_once 'path/to/template.php';
      echo head('Any Page');
      ?>
      <p>This is where the dynamic content goes for this page.</p>
      <?php
      echo foot();
      ?>
      
        Write a Reply...