PHP Template System - Simplified.

1 post Page 1 of 1
Contributors
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

OK, so i will show you how to make a very simple template system using php.
First create your Index.php and add the basic html code to it.
Index.php
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="description" content="" />
	<meta name="keywords" content="" />
	<meta name="author" content="" />
	<link rel="stylesheet" type="text/css" href="css/stylesheet.css" media="screen" />
	<title>My Website Template System</title>
</head>
<body>
	<div class="wrapper">
		<div class="header"><?php include('pages/header.php'); ?></div>
		<div class="topnav"><?php include('pages/topnav.php'); ?></div>
		<div class="sidebar"><?php include('pages/sidebar.php'); ?></div>
		<div class="main"><?php include('pages/main_index.php'); ?></div>
		<div class="footer"><?php include('pages/footer.php'); ?></div>
	</div>
	<br />
</body>
</html>
now if you wish to have the meta data in a seperate file then create a meta.php file in the "pages" folder
meta.php
Code: Select all
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="description" content="" />
	<meta name="keywords" content="" />
	<meta name="author" content="" />
as you can see his is just a simple html file.
now create a folder and name it pages
in the "pages" folder create 5 more php files

header.php
topnav.php
sidebar.php
main_index.php
footer.php


now these page can have any html, javascript, php script that you want in them.
and because they will be in the <BODY></BODY> tags. you can just use simple html tags.No <HEAD> tags.
in these pages, you can query a database to display saved data or run some ajax or what ever you want.
all you will ever need to do is add or edit the pages in the "pages" folder.
Code: Select all
<body>
	<div class="wrapper">
		<div class="header"><?php include('pages/header.php'); ?></div>
		<div class="topnav"><?php include('pages/topnav.php'); ?></div>
		<div class="sidebar"><?php include('pages/sidebar.php'); ?></div>
		<div class="main"><?php include('pages/main_index.php'); ?></div>
		<div class="footer"><?php include('pages/footer.php'); ?></div>
	</div>
	<br />
</body>
to make a new page that the client navigates to say "AboutUs.php"
Then but copy the html from the index.php and paste it to the AboutUs.php
then create a new page in the "pages" folder called main_aboutus.php
then in the <BODY> section of the "AboutUs.php" page change
Code: Select all
<div class="main"><?php include('pages/main_index.php'); ?></div>
to
Code: Select all
<div class="main"><?php include('pages/main_aboutus.php'); ?></div>
this is about the easiest way to make a template system using php.
and is very flexible as well. with alittle practice and some php know how, you can make an awesome php driven website.
Image
1 post Page 1 of 1
Return to “Tutorials”