Jump to content

[SOLVED] PHP template


daveoffy

Recommended Posts

I have been making a HTML and CSS template and just reuse that page and add different PHP files to it and whatever, but when it comes down to changing the look it takes forever since I have to edit every page. How will I go about making a single template page and than just have the other pages just PHP. I searched google but it didn't work out that great since I don't know what to search for.

Link to comment
Share on other sites

A friend and I had built a template system for one of our sites not long ago.  It's actually not all that difficult.

 

None of the pages you navigate to (I.E. domain.com/help.php) should have any HTML in them.  Instead all HTML and CSS should be set in external files broken into modular blocks.  So you might have header.htm, navbar.htm, body.htm, footer.htm.  Your main files like help.php will simply use the include() function to attach the html files where necessary.  Since things like your header wont be changing between pages on the site this lets you edit one HTML file and make a global change to your site.

Link to comment
Share on other sites

A friend and I had built a template system for one of our sites not long ago.  It's actually not all that difficult.

 

None of the pages you navigate to (I.E. domain.com/help.php) should have any HTML in them.  Instead all HTML and CSS should be set in external files broken into modular blocks.  So you might have header.htm, navbar.htm, body.htm, footer.htm.  Your main files like help.php will simply use the include() function to attach the html files where necessary.  Since things like your header wont be changing between pages on the site this lets you edit one HTML file and make a global change to your site.

 

Could you talk to me on aim or something and tell me a little more about it. My aim is daveoffy or you could just reply to this topic.

Link to comment
Share on other sites

Basically we built the HTML page for starters.  We then "chunked" it out, or modularized it.  Each "chunk" went into it's own .htm file in a subdirectory named "templates".  So this file:

 

<html>
<head>
<title>Document</title>
</head>

<body>
<div>This is a header</div>
<div>This is a nav bar</div>
<div>This is the body</div>
<div>This is the footer</div>
</body>
</html>

 

Would be broken into four seperate files, (in this case one for each of those div tags and their content).

 

The PHP file would then look like:

 

<?php
/*Code executed before the html-headers are sent goes here*/
?>

<html>
<head>
<title>PHP TEMPLATE EXAMPLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	/*Code executed before the page head is created goes here*/
	include('/templates/header.htm');
	/*Code executed before the page navigation bar is created goes here*/
	include('/templates/navbar.htm');
	/*Code executed before the page body is created goes here*/
	include('/templates/body.htm');
	/*Code executed before the page footer is created goes here*/
	include('/templates/footer.htm');
?>
</body>
</html>

 

Now when you want to change the page design you simply change header.htm, navbar.htm, body.htm, and footer.htm as needed.  Of course your site will probably be broken down differently, this was a basic example, but you get the point.

Link to comment
Share on other sites

Basically we built the HTML page for starters.  We then "chunked" it out, or modularized it.  Each "chunk" went into it's own .htm file in a subdirectory named "templates".  So this file:

 

<html>
<head>
<title>Document</title>
</head>

<body>
<div>This is a header</div>
<div>This is a nav bar</div>
<div>This is the body</div>
<div>This is the footer</div>
</body>
</html>

 

Would be broken into four seperate files, (in this case one for each of those div tags and their content).

 

The PHP file would then look like:

 

<?php
/*Code executed before the html-headers are sent goes here*/
?>

<html>
<head>
<title>PHP TEMPLATE EXAMPLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
	/*Code executed before the page head is created goes here*/
	include('/templates/header.htm');
	/*Code executed before the page navigation bar is created goes here*/
	include('/templates/navbar.htm');
	/*Code executed before the page body is created goes here*/
	include('/templates/body.htm');
	/*Code executed before the page footer is created goes here*/
	include('/templates/footer.htm');
?>
</body>
</html>

 

Now when you want to change the page design you simply change header.htm, navbar.htm, body.htm, and footer.htm as needed.  Of course your site will probably be broken down differently, this was a basic example, but you get the point.

 

lol. I thought I was so smart when I figured out that trick. it's the fastest way to template. I agree with T-bird's method.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.