PHP to achieve a simple page template replacement effect

Source: Internet
Author: User
Tags header include php and php code

"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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.