Use libtemplate to generate static webpages. Bycoldwindiwindmonthccterraniwind.org has been around for a long time and I have asked people how to implement static web pages, but I am still nagging myself, and now I finally come up with a very simple by coldwind/iwind/month/ccterran http://iwind.org
For a long time, I asked people around how to implement static web pages and asked questions. now, I finally come up with a very simple solution, that is, using libtemplate to implement it.
Look: http://doc.iwind.org
Next I will talk about how to implement static webpage output.
1. modify libtemplate.
Add two functions
// Save the analysis result to a file
Function savetofile ($ dir, $ varname ){
$ Data = $ this-> finish ($ this-> get_var ($ varname ));
$ Fp = fopen ($ dir, "w + ");
Fwrite ($ fp, $ data );
}
The dir in the function is the place where we want to save it in the file. Varname is $ target in libtemplate, which is used as follows:
$ Tpl-> set_file ("main", "main. tpl ");
...
$ Tpl-> parse ("mains", "main ");
$ Tpl-> savetofile ("html/main.html", "mains ");
I believe that readers who understand libtemplate can easily understand this.
// Clear the assigned array
Function renew (){
$ This-> varkeys = array ();
$ This-> varvals = array ();
$ This-> file = array ();
}
In this way, you can clear the impact of the previous template analysis.
2. achieve static output.
If the output is a single file, as shown in the preceding example.
$ Tpl-> set_file ("main", "main. tpl ");
...
$ Tpl-> parse ("mains", "main ");
$ Tpl-> savetofile ("html/main.html", "mains ");
But once we change the document display template, how can we quickly update previously generated static webpages? The following is an example of loop output:
Html_info () {// a single file, just a similar example
Global $ tpl;
$ Tpl-> set_file ("main", "main. tpl ");
...
$ Tpl-> parse ("mains", "main ");
$ Tpl-> savetofile ("html/main.html", "mains ");
$ Tpl-> renew (); // crucial
}
// Cyclic output
For ($ I = 0; $ I <$ total; $ I ++ ){
...
Html_info;
}
Therefore, it is very easy to generate static pages, and updates are not as complicated as you think.
(End)
Http://www.bkjia.com/PHPjc/315097.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/315097.htmlTechArticleby coldwind/iwind/month/ccterran http://iwind.org has been around for a long time I ask others how to implement static web pages, but also to the nagging question, and now, I finally came up with a very simple...