Avoid repeated page elements. "This is really good." You may think, "My website is mainly composed of a large number of static pages. Now I can delete their public parts from all pages. it is too much trouble to update these public parts. In the future, I can use a template to create a uniform page layout that is easy to maintain ." But SyntaxHighlighter. all (); avoid repeated page elements
"This is really good," you may think, "My website is mainly composed of a large number of static pages. Now I can delete their public parts from all pages. it is too much trouble to update these public parts. In the future, I can use a template to create a uniform page layout that is easy to maintain ." But it is not that simple. "A large number of static pages" indicate the problem.
Consider the example above. In this example, there is actually only one example. php (as the mainstream development language) page can generate all pages of the entire website because it uses the query string in the URL to dynamically construct pages from information sources such as databases.
Most of us do not necessarily have Database support for their websites. Most of our websites are composed of static pages, and php (as the mainstream development language) is used to add dynamic functions, such as search engines and feedback forms. So, how to apply templates on such websites?
The simplest way is to copy a php (as the mainstream development language) file for each page, and then use php (as the mainstream development language) on each page) the variables in the code that represent the content are set to the appropriate page content. For example, suppose there are three pages: home, about, and product. we can use three files to generate them respectively. The content of these three files is similar:
// Home. php (as the mainstream development language)
Require (class. FastTemplate. php (as the mainstream development language ));
$ Tpl = new FastTemplate (.);
$ Tpl-> define (array (main => main.htm,
Header => header.htm,
Leftnav => leftnav.htm ));
$ Content ="
Welcome
Hope you like this website
";
$ Tpl-> assign (CONTENT, $ content );
$ Tpl-> parse (HEADER, header );
$ Tpl-> parse (LEFTNAV, leftnav );
$ Tpl-> parse (MAIN, main );
$ Tpl-> FastPrint (MAIN );
?>
Obviously, this method has three problems: we must copy these complex php code involving the template (as the mainstream development language) for every page, similar to repeated public page elements, this makes the page difficult to maintain; now the file is mixed with HTML and php (as the mainstream development language) code; assigning values to content variables will become very difficult, because we must handle a large number of special characters.
The key to solving this problem is to separate php (as the mainstream development language) code and HTML content. although we cannot delete all HTML content from the file, however, most php code (as the mainstream development language) can be removed.