Developing Webs logo
Google
Web DW-Main DW-Photoshop
Visit the message board for solutions or post a question Check out the Classes offered for free at Developing Webs Voice Chat submit a tutorial, resources, article, font for publication consideration and earn a one way link back to your site Get more specifics about the Developing Webs Voice chat room and its room members View the current news at Developing Webs alternative sites which are resources for your d3evelopment needs Join Developing Webs Chat Link to us on your web page to help support this resource! Check out Developing Webs At yahoo groups! Developing Webs Home Adobe Photoshop Tutorials Macromedia Flash Tutorials Jasc Paint Shop Pro Tutorials Adobe Illustrator Animation basics Some Basic PHP tutorials Perl Tutorials HTML Tutorials Cascading Style Sheets javascript Front Page Tutorials Macromedia Dream Weaver Tutorials dreamweaver Publishing your site, FTP, ChMod, Promotions Tools to help you create your site Free and shareware fonts to download Photographs to use in your projects Shop for your site needs Free Online classes REcommend this site to others Log in or edit your information when logged in Developingwebs Log Out Change My Account details and preferences
RSS Newsfeed
for your site
DW News
Calendar
DW Forum
Right click on button and copy shortcut

Add to My Yahoo!

Reminder
Remember to book mark this site!



Request a Tutorial

PHP: Using Included Content for your template

Page template is repeated over and over within a site. the layout of the template generally does not change. Because of this, it lends itself to be includes for each of your page. This will eliminate recreating the template each time.

  • In the tutorial you will be breaking apart a template to create includes that will not change, so when reconstructed in PHP it will display correctly.

A graphic template created say in Photoshop is sliced into a table format, so that the content area is generally enclosed in a table cell. If done right, your template could be included into each page with PHP commands and when you change the template, you will change all your pages.

The Layout of a template will look like this:

CODE

What I will call it in the class

<html>
<head>


</head>

This is the head of your document. It contains the metatags, pagename, and scripts used in the page.
<body>
<TABLE>
<TR>
<TD>
</td>
More template stuff
<TD>
This is the top part of the table which contains all the template that is to the left and above the content cell.
YOUR CONTENT CELL HERE
 
This is the content cell of your template
</TD>
</TR>
possibly more template stuff
</TABLE>
This is the bottom and right of your template.
</body>
</html>
End of your HTML doc.

If you think about pages and what is specific for any one URL and what is in common with a group of pages, you can save time by using includes.

  • In this case each page uses a unique title and metatag so this should not be in a include.
  • The top part of the table is common on each page and can be used in an include.
  • The content of your template can be written in simple html, with little formatting and included for each page (or not included as it changes in each page depending on your style or use of data base)
  • The bottom of the table template is the same in each page and so is the end of the page.

Include basics

  • An Included file can be PHP, text, html or other.
  • Any HTML formatting within the included file will be interpreted in the page.
  • If your included file is a php file, the php coding within it will be interpreted for the inclusion.
  • The included file can be a relative link or an exact URL. Some servers do not allow linking includes from other domains and therefore will only allow relative URLS.
  • An Include in PHP looks like this:
    <?
    include ("includedfile.php");
    ?>
  • All relative links in your included file will be interpreted as relative links from the location of your file the include is contained in.

Include Activity

1. Create the html template as described in this tutorial of a basic html template.

2. Add the PHP Copyright code into your template from this tutorial and rename your template with a php extension.

3. Set up an include for the content cell of your document. Call your content page mypage.htm.

<?
include ("mypage.htm");
?>

4. Use a text file or php file or html document you already have on your site that is not in a template. Please the include in your document. The code will look like this:

<html>
<head>
<title>HTML Web Page Template</title>
</head>
<body>
<table width="780" align="center" border="1" bordercolor="#000000">
<tr>
   <td colspan="2" bgcolor="#000080" align="center">
     <h1 style="color:white">Developing Webs Group</h1>
     <h5 style="color:white">A Web Development Community</h5>
   </td>
</tr>
<tr>
   <td bgcolor="#000080" width="120" align="center">
     <h4 style="color:white">Photoshop</h4>
     <h4 style="color:white">HTML</h4>
     <h4 style="color:white">PHP</h4>
     <h4 style="color:white">Flash</h4>
     <h4 style="color:white">CSS</h4>
     <h4 style="color:white">MessageBoard</h4>
     <h4 style="color:white">Contact</h4>
     <h4 style="color:white">Home</h4>
   </td>
   <td bgcolor="#ffffff" width="660">
     <?
     include ("mypage.htm");
     ?>

   </td>
</tr>
<tr>
   <td colspan="2" bgcolor="#000080" align="center">
     <?
     //Provided by Developingwebs.net
     echo "Copyright &copy; 1998-".date('Y');
     ?>
   </td>
</tr>
</table>
</body>
</html>
 

5. Create an include file for the top of the template. Copy the top of the table for the template into a new document called topinclude.htm. For the template above, The source for the file will look like this:

<body>
<table width="780" align="center" border="1" bordercolor="#000000">
<tr>
   <td colspan="2" bgcolor="#000080" align="center">
     <h1 style="color:white">Developing Webs Group</h1>
     <h5 style="color:white">A Web Development Community</h5>
   </td>
</tr>
<tr>
   <td bgcolor="#000080" width="120" align="center">
     <h4 style="color:white">Photoshop</h4>
     <h4 style="color:white">HTML</h4>
     <h4 style="color:white">PHP</h4>
     <h4 style="color:white">Flash</h4>
     <h4 style="color:white">CSS</h4>
     <h4 style="color:white">MessageBoard</h4>
     <h4 style="color:white">Contact</h4>
     <h4 style="color:white">Home</h4>
   </td>
   <td bgcolor="#ffffff" width="660">

Simply take the top part of the code for the table, above the content include and paste it into a text file. Click File=> save as. Set the filename to topinclude.htm and set the filetype to all files. Place this in the same directory as my template file.

6. Create an include file for the bottom of the template. Copy the top of the table for the template into a new document called bottominclude.php. This must be a PHP file since it includes a PHP script for copyright. For the template above in #4, The source for the file will look like this:

   </td>
</tr>
<tr>
   <td colspan="2" bgcolor="#000080" align="center">
     <?
     //Provided by Developingwebs.net
     echo "Copyright &copy; 1998-".date('Y');
     ?>
   </td>
</tr>
</table>
</body>
</html>

7. Create the include statements to be placed in the top of the table template and the bottom of the table include statements so that your original template document now looks like this:

 <html>
<head>
<title>HTML Web Page Template</title>
</head>
      <?
     include ("topinclude.htm");
     ?>

     <?
     include ("mypage.htm");
     ?>
      <?
     include ("bottominclude.php");
     ?>

8. Save your new template as a php and test it on a php server. Look at the source code when you have it in a broswer and check out how the scripts are interpreted into html!



"Building The Web Into a Nicer Place -- One Site At A Time"
Developing Webs Group Copyright © 2001-2010 All Rights Reserved
Privacy and Legal