Use libtemplate to generate static web pages _ PHP Tutorial

Source: Internet
Author: User
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...

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.