"This template is good, use it? No, look down. Well, this is good, either ...
It was the first day I had come to the point where I did it--pick the template. A little aesthetic template let people amoy drunk.
Below the use of PHP to achieve a simple page template replacement.
First post the engineering directory structure:
Tpl_test for the engineering directory, templates directory has two templates, 1 and 2, here only replace the head and tail effect, so there are only two files footer.php and header.php.
The following code is posted in the index.php:
<?php
Simple Replacement Template Example
$TPL = isset ($_get[' TPL ')? $_get[' TPL ']:1;//defaults to the first template
Include "templates/". $tpl. " /header.php ";//header
?>
<?php
Include "templates/". $tpl. " /footer.php ";//footer
?>
The code needs to do some judgment on $_get[' TPL ', which is omitted here.
$TPL variable to get the name of the template, in order to facilitate, this selection of the URL to pass (you can get the template name from various sources, such as the database), and then load the corresponding header.php and footer.php according to the template name, plainly, is to change the path load page template.
Only the header.php code for template 1 is posted below, and template 2 only needs to be changed accordingly:
<title>
This is a template
</title>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
<body>
<a href= "index.php?tpl=1" > Template one </a>
<a href= "index.php?tpl=2" > Template two </a>
<br/>
<p> This is the head of template one </p>
The code is simple and does not prefix it. The following effect chart:
Template one:
Template two:
It's just a primer.
There are too many ways to achieve page template replacement, it depends on how you create, how to play the imagination.
No need to worry about how simple the above code, how useless.
When you peek into the complex interior, you will find many simple.