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 );
}
?>