Realize static web page with libtemplate

zhaozj2021-02-12  131

Implement static web generation with libTemplate 2004-06-16 Click: 5

Realize static web page with libtemplate

I have been a long time, I will ask others how to implement a static page, and I have mentioned the problem, and now, I finally came up with a very simple way, that is to use libTemplate to implement it. Let's see: http://doc.iwind.org Let me talk about how to implement a static web output. 1. Modify libTemplate. Add two functions // save the analysis results to Function Savetofile ($ DIR, $ VarName) {$ data = $ THIS-> Finish ($ this-> get_var ($ varname)); $ FP = FOPEN ($ DIR, "W "); fwrite ($ fp, $ data);} Dir in the function is where we have to save in the file. Varname is $ target in libtemplate, using the following: $ TPL-> Set_file ("main", "main.tpl"); ... $ TPL-> Parse ("MAINS", "Main"); $ TPL-> Savetofile ("html / main.html", "mains"); believe that LibTemplate readers can easily understand this. // Clear the assigned array Function Renew () {$ this-> varkeys = array (); $ this-> VARVALS = array (); $ this-> file = array ();} This can clear the influence of the previous template analysis. 2. Realize the static output. If the output is a single file as an example above. $ TPL-> set_file ("main", "main.tpl"); ... $ TPL-> Parse ("MAINS", "Main"); $ TPL-> Savetofile ("html / main.html", "mains"); but Once we changed the template displayed by the article, how to make the previously generated static web page quickly update? Obviously, you want to loop output. Examples are as follows: html_info () {// 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 (); // Vocal Important} // Cycle Output for ($ I = 0; $ I <$ TOTAL; $ I ) {... HTML_INFO;} So the implementation of the static page is very Simple. Update is not as complex in the imagination. (End)

转载请注明原文地址:https://www.9cbs.com/read-7433.html

New Post(0)