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 ',