Webmaster Forum  

Go Back   Webmaster Forum > Website Design Forum > Website Design Forum
User Name
Password
Register FAQ Members List Calendar Transactions Store Search Today's Posts Mark Forums Read


Template engine with PHP

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-18-2005, 18:55
admans
Senior Member


Join Date: Jul 2005
Posts: 248
Trader Rating: (0)
Points: 22 (Donate)
5 F$/Referral Refer Friends
admans is on a distinguished road
Default Template engine with PHP

How to use PHP to make a template system with static header/footer.

Abstract:
First we assume that we have a root folder and that all the files we need are in it.
Let's say that we have header.html, footer.html, content1.html, content2.php, main.html, and finally error.html.
Our goal is to use static header (header.html) and footer (footer.html) while the content in between is changing (content1.html, content2.php, main.html).
In the case where no page is selected the main page (main.html) will be displayed by default and if the name does not exist it will display the error page (error.html).
Notice that the content page as we name it can be HTML or PHP.

PHP Code:
The file that is used for the template system is called index.php and contains the following code:
PHP Code:
<?php

/*--TEMPLATE HEADER--*/

include_once("header.html");

/*--TEMPLATE CONTENT--*/

// Default page main.html
// If does not exist error.html

if(!isset($_GET['page'])){
    include_once(
'main.html');
} else {
    
$pagename $_GET['page'];
switch(
$pagename)
{
    case 
content1:
$page "content1.html";
    break;
    case 
content2:
$page "content2.php";
    break;
    default:
$page "error.html";
}
include_once(
$page);
}



/*--TEMPLATE FOOTER--*/

include_once("footer.html");

?>

You can add as many page as you want by adding some cases to the switch() function.

Example:
HTML Code:
case whatever:
$page = "whatever.php";
    break;


This code can be repeated infinitely as long as the name is unique.

Browsing URL's
Once everything is ready and uploaded to your server web space, you can call any page you want by using:
index.php?page=pagename. In our example above it will be index.php?page=whatever. If you give a page name that does not exist, it will automatically forward you to error.html and if you go directly to the index.php page, it will display main.html by default.



Source Script by my friend: o0slowpaul0o
Pleas keep his copyright in the footer.Got permission from him to post this topic.
Attached Files
File Type: zip templatesystem.zip (7.6 KB, 8 views)
__________________

http://img76.imageshack.us/img76/6450/sc2but4ng.gif | http://img495.imageshack.us/img495/...ogorwtan0je.gif | <a href="http://webtools.sc2.info"><img src="http://img129.imageshack.us/img129/8682/sc2webtan7ju.gif" border="1" width="100" alt="Free Webtools for all" /></a> | <a href="http://www.indexrated.com"><img src="http://img398.imageshack.us/img398/4813/listed1pb.gif" border="1" width="100" alt="Index Rated Directory - Rating Quality Sites" /></a>

Get all Games,Apps and Wallpapers Nokia, Samsung and Sony Erricson!!

admans is offline
Reply With Quote
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Resources : | Advertise at FHF | itextLink.com| Reseller Hosting| TextDot| iNamePros| Any Webmaster| Web Host| Dep3| cheap low cost web hosting reviews|


All times are GMT -4. The time now is 12:37.


Powered by: vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.