Use PHP to create a static website template framework (4)

Source: Internet
Author: User
Static website template framework: first, we write template files for all the common page elements and the overall layout of the page as before; then, we delete the public part from all the pages, leaving only the page content; next, add three lines of php code (as the mainstream development language) to each page, as shown below: & lt ;? PhpSyntaxHighlighter. all (); static website template framework

First, we will write a template file for all the common page elements and the overall layout of the page as before. then, we will delete the public part from all the pages, leaving only the page content; next, add three lines of php code (as the mainstream development language) to each page, as shown below:







Hi!

Welcome



Hope you like this website





?>

This method basically solves the various problems mentioned above. Currently, there are only three lines of php (as the mainstream development language) code in the file, and no line of code directly involves the template, so it is very unlikely to modify the code. In addition, because the HTML content is located outside the mark of php (as the current mainstream development language), there is no special character processing problem. We can easily add these three lines of php code (as the mainstream development language) to all static HTML pages.

The require function introduces a php (as the current mainstream development language) file, which contains all the necessary template-related php (as the current mainstream development language) code. The pageStart function sets the template object and page title. the pageFinish function parses the template and generates the result and sends it to the browser.

How is this implemented? Why does the HTML in the file not be sent to the browser before calling the pageFinish function? The answer is that php (as the mainstream development language) 4 is a new function that allows the browser to intercept the content to the buffer. Let's take a look at the specific code of prepend. php (as the mainstream development language:


Require (class. FastTemplate. php (as the mainstream development language ));

Function pageStart ($ title = ){
GLOBAL $ tpl;
$ Tpl = new FastTemplate (.);
$ Tpl-> define (array (main => main.htm,
Header => header.htm,
Leftnav => leftnav.htm ));
$ Tpl-> assign (TITLE, $ title );
Ob_start ();
}

Function pageFinish (){
GLOBAL $ tpl;
$ Content = ob_get_contents ();
Ob_end_clean ();
$ Tpl-> assign (CONTENT, $ content );
$ Tpl-> parse (HEADER, header );
$ Tpl-> parse (LEFTNAV, leftnav );
$ Tpl-> parse (MAIN, main );
$ Tpl-> FastPrint (MAIN );
}

?>

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.