Use PHP to create a static website template framework

Source: Internet
Author: User
The template can improve the website structure. This article describes how to use a new function and template class of PHP4 to control the page layout in a website composed of a large number of static HTML pages. Outline: =

The template can improve the website structure. This article describes how to use a new function and template class of PHP 4 to control the page layout in a website composed of a large number of static HTML pages.

Outline:

==========================================

Efficacy and layout

Avoid repeated page elements

Static website template framework

==========================================

Efficacy and layout


First, let's take a look at the two important goals of using the template:

Efficacy (PHP) and layout (HTML) respectively)

Avoid repeated page elements

The first objective is the most talked about. it is assumed that a group of programmers write PHP scripts for natural page content, at the same time, another group of design staff designed HTML and graphics to hold the ultimate appearance of the page. The basic idea of efficacy and layout is to enable the two groups to write and apply independent files: programmers only need to care about files that only contain PHP code, the page design staff can design the page layout with their most familiar visual editor without worrying about damages to any PHP code embedded into the page.

If you have read several tutorials on PHP templates, you should have understood the working mechanism of the template. Consider a simple page: the top of the page is the page header, the left is the navigation bar, and the rest is the content area. Such websites can have the following template files:



Template example



{HEADER}
{LEFTNAV} {CONTENT}








Foo

Bar

We can see how the page is structured by these templates: the main template controls the layout of all pages; the header template and the leftnav template hold the public elements of the page. The identifier in the braces "{}" is a content placeholder. The most important benefit of an application template is that the interface designer can compile these files as needed, such as setting fonts, correcting colors and graphics, or completely changing the layout of pages. Interface designers can use any common HTML editor or visualization tool to compile these pages. because these files only contain HTML code, there is no PHP code.

All PHP code is stored in a separate file. This file is actually called by the page URL. The Web server parses the file through the PHP engine and returns the result to the browser. Generally, PHP code dynamically generates page content, such as querying a database or performing a certain calculation. The following is an example:


  
// Example. php
Require ('class. FastTemplate. php ');
= New FastTemplate ('.');
-> Define (array ('main' => 'main.htm ',

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.